Hey all,
I have a variable that's CHAR with length16 (2014-07-01 00:15). I want to convert this to a DATETIME, so I tried the INPUT statement.
date = input(date1,datetime.);
Any help would be appreciated, thanks!
please try the informat anydtdtm20.
data have;
date1='2014-07-01 00:15';
date = input(date1,anydtdtm20.);
format date datetime20.;
run;
Thanks,
Jag
please try the informat anydtdtm20.
data have;
date1='2014-07-01 00:15';
date = input(date1,anydtdtm20.);
format date datetime20.;
run;
Thanks,
Jag
There are various ways of doing it, mdy function etc. Its more about selecting the appropriate formats for the data. Below I show some which will get you the result (note you can combine the steps, have them here just as a descriptive). Anyways, probably easiest is the anydtdtm informat.
data want;
attrib a format=$16. b format=date9. c format=tod5. d format=datetime. e format=datetime.;
a="2014-07-01 00:15";
b=input(substr(a,1,10),yymmdd10.);
c=input(substr(a,12,5),time5.);
d=input(put(b,date9.)||":00"||put(c,tod5.),datetime.);
e=input(a,anydtdtm.);
run;
Thanks guys! Both very helpful answers.
Steve
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.