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

Hi there

 

I have a column of data like 201701011200, the format of which is character (YYYYMMDDHHMM). I'd like to transform them to datetime format and I used input() function while it didn't work. Could you guys help me solve this question?

 

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Am sure there is an informat for it, but just can't think, so to do it by function:

data want;
  a="201701011200";
  b=dhms(input(substr(a,1,8),yymmdd8.),input(substr(a,9,2),best.),input(substr(a,11,2),best.),0);
  format b datetime.;
run;

View solution in original post

4 REPLIES 4
Reeza
Super User

INPUT is correct. Post your code and explain what doesn't work means because we can't see your computer 🙂 

If you can't find the correct informat, try ANYDTDTM. 

 


@sfps01 wrote:

Hi there

 

I have a column of data like 201701011200, the format of which is character (YYYYMMDDHHMM). I'd like to transform them to datetime format and I used input() function while it didn't work. Could you guys help me solve this question?

 

Thank you 


 

sfps01
Calcite | Level 5

Thank you Reeza for your response. I tried input(COLUMN_NAME, datetime20.) as Datetime_trans and input(COLUMN_NAME, ANYDTDTM.) as Datetime_trans. Neither worked since the column Datetime_trans was blank after I ran my program.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Am sure there is an informat for it, but just can't think, so to do it by function:

data want;
  a="201701011200";
  b=dhms(input(substr(a,1,8),yymmdd8.),input(substr(a,9,2),best.),input(substr(a,11,2),best.),0);
  format b datetime.;
run;
sfps01
Calcite | Level 5

Thank you so much! Your codes works. Appreciate your help

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
  • 4 replies
  • 1920 views
  • 0 likes
  • 3 in conversation