问题
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.
回答1:
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;
回答2:
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;
回答3:
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.
来源:https://stackoverflow.com/questions/31991855/sas-not-recognizing-date-format