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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.