Hi. I have a SAS dataset text field which looks as follows 2014-11-27 07:02:33.608355
How do I convert this to a SAS DateTime Format field ?
Try informat: anydtdtm.
data x; a='2014-11-27 07:02:33.608355'; b=input(a,anydtdtm30.); format b datetime.; run;
Xia Keshan
The usual way is by input(variable,dateformat)
With regards to your format, it is a sort of iso date, so other than the 608355 (which to be honest I would have to look up, probably timezone offset or something), you could do:
input(substr(variable,1,10)||"T"||substr(12,5)||":00",e8601dt.)
Just a matter of pulling out the info you need.
Try informat: anydtdtm.
data x; a='2014-11-27 07:02:33.608355'; b=input(a,anydtdtm30.); format b datetime.; run;
Xia Keshan
Many thanks Xia - your proposal works perfectly.
Given that your input has microsecond precision, you may also find this thread useful:
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.