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