BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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
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
Pyrite | Level 9

That worked! Many thanks! 🙂

 

- Dr. Abhijeet Safai

Dr. Abhijeet Safai
Associate Data Analyst
Actu-Real

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 403 views
  • 1 like
  • 2 in conversation