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

I am using SAS Enterprise Guide and I am trying to format a text field by the name of 'Admit Date' with data such as: 20180110164700 to a datetime format.  Hopefully formatted to YYYY-MM-DD HH:MM:SS.  Any help would be appreciated.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
cmcquain
Fluorite | Level 6
I got it! I had to change substring count on minutes and seconds.

DHMS(input(substr(t3.'Admit Date'n,1,8),yymmdd8.),input(substr(t3.'Admit Date'n,9,2),hh2.),input(substr(t3.'Admit Date'n,11,2),mm2.),input(substr(t3.'Admit Date'n,13,2),ss2.))

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, in code you do (and this assumes I am right on what the date should be - really a good idea to get the sender to apply some sort of standard date format to the data, something like ISO dates):

data want;
  set have;
  mydt=dhms(input(substr(text,1,8),yymmdd8.),input(substr(text,9,2),best.),input(substr(text,10,2),best.),input(substr(text,12,2),best.));
  format mydt datetime.;
run;
cmcquain
Fluorite | Level 6
I had to modify your code some as shown DHMS(input(substr(t3.'Admit Date'n,1,8),yymmdd8.),input(substr(t3.'Admit Date'n,9,2),hh2.),input(substr(t3.'Admit Date'n,10,2),mm2.),input(substr(t3.'Admit Date'n,12,2),ss2.)) Format = DATETIME19. I am still getting the wrong output. From the original 20180110164700 I am getting this 10JAN2018:17:05:10 when the field should look like 10JAN2018:16:47:00
cmcquain
Fluorite | Level 6
I got it! I had to change substring count on minutes and seconds.

DHMS(input(substr(t3.'Admit Date'n,1,8),yymmdd8.),input(substr(t3.'Admit Date'n,9,2),hh2.),input(substr(t3.'Admit Date'n,11,2),mm2.),input(substr(t3.'Admit Date'n,13,2),ss2.))

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2770 views
  • 0 likes
  • 2 in conversation