BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ani_Abby
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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;

 

 

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

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;

 

 

Norman21
Lapis Lazuli | Level 10

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/

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

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
  • 3 replies
  • 957 views
  • 2 likes
  • 3 in conversation