I have a character ISO date like 1985-01-26T01:32. It is in character. I want to convert it into a numeric date where I can do mathematical operations. I want to know if there is any way in which I can do it directly.
I know indirect way of using substr function, to get date and time part separate and then applying dhms function do it. But that is an indirect way. I wan to know if there is any direct way.
Thanks in advance! 🙂
- Dr. Abhijeet Safai
data have;
y='1985-01-26T01:32';
run;
data want;
set have;
dt=input(y,E8601DT.);
format dt datetime19.;
run;
PS: Never NEVER treat character dates or character datetimes as text, where you have to operate on it via SUBSTR() or other character functions. Convert them to numeric as shown above.
data have;
y='1985-01-26T01:32';
run;
data want;
set have;
dt=input(y,E8601DT.);
format dt datetime19.;
run;
PS: Never NEVER treat character dates or character datetimes as text, where you have to operate on it via SUBSTR() or other character functions. Convert them to numeric as shown above.
That worked! Many thanks! 🙂
- Dr. Abhijeet Safai
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.