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.
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.);
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;
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!
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.