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
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.