BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
DrAbhijeetSafai
Lapis Lazuli | Level 10

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

Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
Associate Data Analyst
Actu-Real
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
DrAbhijeetSafai
Lapis Lazuli | Level 10

That worked! Many thanks! 🙂

 

- Dr. Abhijeet Safai

Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
Associate Data Analyst
Actu-Real

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1222 views
  • 1 like
  • 2 in conversation