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

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1701 views
  • 2 likes
  • 3 in conversation