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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1202 views
  • 0 likes
  • 3 in conversation