BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alan0101
Obsidian | Level 7

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Try informat:  anydtdtm.

data x;
 a='2014-11-27 07:02:33.608355';
 b=input(a,anydtdtm30.);
 format b datetime.;
 run;

Xia Keshan

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User

Try informat:  anydtdtm.

data x;
 a='2014-11-27 07:02:33.608355';
 b=input(a,anydtdtm30.);
 format b datetime.;
 run;

Xia Keshan

alan0101
Obsidian | Level 7

Many thanks Xia - your proposal works perfectly.

jdmarino
Fluorite | Level 6

Given that your input has microsecond precision, you may also find this thread useful:

https://communities.sas.com/message/223311#223311

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1875 views
  • 1 like
  • 4 in conversation