Hi
I have a text variable containg dates in the format:
YYYY-MMM-DD
2011-FEB-14
2002-SEP-22
etc
I'm trying to convert these to SAS dates using input statement but get invalid data message for the INPUT statement
Any help on how to get this working
eg
data test;
date1='2011-AUG-12';
date2=input(date1,yymmdd11.);
run;
Thanks
Steve
anydtdte11.
Hi Steve
I do not know of a format, but you can write a function to make a SAS date value out of the string, see sample below:
Bruno
How about:
data test;
date1='2011-AUG-12';
date2=input(substr(date1,10,2)||substr(date1,6,3)||substr(date1,1,4),date9.);
put date1= date2= ;
run;
anydtdte11.
data test;
date1='2011-AUG-12';
date2=input(date1,anydtdte11.);
format date2 mmddyy10.;
run;
proc print;run;
Thanks - does the job!...now to read up on it......
Not a lot to look up on it (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002605538.htm), but the anydtdte informat appears to be able to read dates that give all of the other date informats problems. A useful system option to supplement it is the:
options datestyle=mdy
in order to guide the informat regarding the order of the three date parts.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.