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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.