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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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