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

Hello,

 

I have a date variable that looks like the following:

2020-08-26 09:16:36 and it is a character

 

I ran the following code to try and convert the code to mmddyy10. format but it is not working.

data want;

set have;

ps_ts= substr(patient_survey_timestamp, 1, 10);
pat_suv_date = input(ps_ts, mmddyy10.);

run;

 

Obviously, I am applying the code incorrectly, does anyone know the correct way to run this code? Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you only want the date part of the value read with the correct informat.

one way

data example;
   x="2020-08-26 09:16:36";
   date = input(x,yymmdd10.);
   format date mmddyy10.;
run;

The value of the date portion of the string is in year month day order. Whey you use MMDDYY for the informat then you are reading month day year.

View solution in original post

1 REPLY 1
ballardw
Super User

If you only want the date part of the value read with the correct informat.

one way

data example;
   x="2020-08-26 09:16:36";
   date = input(x,yymmdd10.);
   format date mmddyy10.;
run;

The value of the date portion of the string is in year month day order. Whey you use MMDDYY for the informat then you are reading month day year.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 1116 views
  • 0 likes
  • 2 in conversation