DATA Step, Macro, Functions and more

how to convert string as 'Wed Sep 15 12:28:27 2010' to datetime variable

Reply
N/A
Posts: 0

how to convert string as 'Wed Sep 15 12:28:27 2010' to datetime variable

Hi, all!

when i get the datetime stirng as 'Wed Sep 15 12:28:27 2010', how can i convert it to a datetime variable.
use the NLDATM function, you can give a format descriptor, then can get the datetime part, so, can i use a descriptor as '%a %b %d %H:%M:%S %Y', then can convert the string to a datetime variable?
Regular Contributor
Posts: 171

Re: how to convert string as 'Wed Sep 15 12:28:27 2010' to datetime variable

Instead of using the NLDATM function, would something like this work?

data _null_;
worddate = 'Wed Sep 15 12:28:27 2010';
numberdate = input(scan(worddate, 3, ' ')!!scan(worddate, 2, ' ')!!scan(worddate, 5, ' ')!!':'!!scan(worddate, 4, ' '), datetime18.);
put 'The SAS date ' numberdate 'is ' worddate;
run;
N/A
Posts: 0

Re: how to convert string as 'Wed Sep 15 12:28:27 2010' to datetime variable

Thanks very much!
Ask a Question
Discussion stats
  • 2 replies
  • 128 views
  • 0 likes
  • 2 in conversation