DATA Step, Macro, Functions and more

Text DateTime Field to SAS DateTimeField

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Text DateTime Field to SAS DateTimeField

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 ?


Accepted Solutions
Solution
‎11-28-2014 09:03 AM
Super User
Posts: 9,682

Re: Text DateTime Field to SAS DateTimeField

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


All Replies
Super User
Super User
Posts: 7,405

Re: Text DateTime Field to SAS DateTimeField

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.

Solution
‎11-28-2014 09:03 AM
Super User
Posts: 9,682

Re: Text DateTime Field to SAS DateTimeField

Try informat:  anydtdtm.

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

Xia Keshan

Contributor
Posts: 40

Re: Text DateTime Field to SAS DateTimeField

Many thanks Xia - your proposal works perfectly.

Frequent Contributor
Posts: 78

Re: Text DateTime Field to SAS DateTimeField

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

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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