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
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;
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
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.
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;
Thank you so much! Your codes works. Appreciate your help
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!
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.