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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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