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/
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.
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.