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:
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.