I've been searching function or a way to convert datetime DDD MON DD HH:MM:SS YYYY (e.g Tue Oct 31 01:30:31 2017) I received from datalist to DATETIME19. At the moment I use SQL CASE format, FIND function and temporary field to get day, month, year, hour, minute and second.
I'm using SAS 9.2
Your date is weird enough that you must parse the string.
Here is one way:
data _null_;
A='Tue Oct 31 01:30:31 2017';
B=input(scan(A,3)||scan(A,2)||scan(A,5,' ')||':'||scan(A,4,' '),datetime.);
run;
Your date is weird enough that you must parse the string.
Here is one way:
data _null_;
A='Tue Oct 31 01:30:31 2017';
B=input(scan(A,3)||scan(A,2)||scan(A,5,' ')||':'||scan(A,4,' '),datetime.);
run;
If the variable is a datetime number (the number of seconds from midnight 1 January 1960), then you can apply any of a range of datetime formats to display the data as you wish.
If the variable is not a datetime number, then you have to extract the components and re-assemble them. If you do this correctly, you can convert the result into a SAS datetime number, then apply a format as described above.
Some advice on coding can be found here:
https://blogs.sas.com/content/sasdummy/2011/11/15/do-you-mind-if-we-dance-with-your-dates/
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: