Josh
Josh

Reputation: 3311

SAS not recognizing date format

I have the following character date format:

"3/1990"
"4/1990"
"5/1990"
...

I tried the following code:

data work.temps;
  set indata;
  newdate = input(strip(Date), MMYYSw.);
  rename newdate = date;
run;

I keep on getting the following error meassage: Informat MMYYSW was not found or could not be loaded.

Upvotes: 3

Views: 1562

Answers (3)

Shenglin Chen
Shenglin Chen

Reputation: 4554

Try this with anydtdte:

data have;
    input date $10.;
    _date=input(compress(date,'""'),anydtdte.);
    format _date MMYYs7.;
    cards;
    "3/1990"
    "4/1990"
    "5/1990"
    ;
    run;

Upvotes: 3

vasja
vasja

Reputation: 4792

What you refer is a FORMAT, not INformat. You'll use format with PUT function, for INPUT, you need informat.

Anyway I didn't find a suitable informat to be used directly, so you'll need to do more stuff:

data work.temps;
infile cards truncover;
input Date $10.;
newdate=MDY( scan(Date,1, '/'), 1, scan(Date,2, '/') );
cards;
3/1990
4/1990
5/1990
;
run;

SCAN takes Nth word from a string, MDY creates DATE from Month, Day and Year. The code above gives the first day of the month.

Upvotes: 1

ander2ed
ander2ed

Reputation: 1338

You may have to use a different informat to read in the character dates so that SAS can interpret them as numeric (since dates in SAS are actually numeric values), and then format them as MMYYS..

This was tested and works for me:

DATA temps;
FORMAT newdate MMYYS.;
SET indata;
newdate = INPUT(COMPRESS('01/'||date),DDMMYY10.);
RUN;

Upvotes: 6

Related Questions