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;

 

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