BookmarkSubscribeRSS Feed
SR11
Obsidian | Level 7

I want to convert my CHARACTER DATE TIME to NUMERIC DATE:

Data I have:

Date_time

Var1

06/03/2017 19:37

A

09/23/2015 15.33

B

06/06/2019 00:48

C

05/05/2018 12.34

D

 

Data I want

Date_num

Var1

06/03/2017

A

09/23/2015

B

06/06/2019

C

05/05/2018

D

 

 

Thank you very much. 

2 REPLIES 2
Kurt_Bremser
Super User

Use

num_date = input(substr(date_time,1,10),mmddyy10.);
format num_date mmddyy10.;

It might be possible to omit the SUBSTR:

num_date = input(date_time,mmddyy10.);
GraphGuy
Meteorite | Level 14

Or the following variation, using the scan() function to parse out the date part from the string, rather than relying on it to be a length of 10 ... just in case any of the day or month values aren't padded on the left with the zero:

 

data foo;
date_time='06/03/2017 19:37';
date_num=input(scan(date_time,1,' '),mmddyy10.);
format date_num mmddyy10.;
run;

 

proc print data=foo; run;

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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