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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.