I have a date and time being sent to me in raw text format and I need to convert it to sas data format mmddyy10. I thought I could do this with a format statement, but not having much luck. Any help would be greatly appreciated.
data rawdata;
input last_run_date $1-20;
datalines;
9-sep-2018 08:04:54
9-sep-2018 08:01:41
9-sep-2018 07:01:28
9-sep-2018 05:06:23
9-sep-2018 05:06:21
31-oct-2017 14:56:35
31-oct-2017 11:08:46
31-oct-2017 10:17:21
31-may-2015 00:01:11
31-mar-2018 12:25:20
;
data want;
09/09/18
09/09/18
09/09/18
09/09/18
09/09/18
10/31/17
10/31/17
10/31/17
05/31/15
03/31/18
If you use the proper informat when you read the data in, you get actual numeric SAS date time values, and then these can be displayed as mmddyy10.
data rawdata;
input last_run_date anydtdtm24.;
date=datepart(last_run_date);
format date mmddyy10.;
datalines;
...
;
If you use the proper informat when you read the data in, you get actual numeric SAS date time values, and then these can be displayed as mmddyy10.
data rawdata;
input last_run_date anydtdtm24.;
date=datepart(last_run_date);
format date mmddyy10.;
datalines;
...
;
Thank you! I was trying to convert after the fact. This is awesome thank you!!!
After the input, you can still do this
data rawdata;
input last_run_date $1-20;
date=datepart(input(last_run_date,anydtdtm24.));
format date mmddyy10.;
datalines;
...
;
No need to read the time variable in the first place, like
data rawdata;
input last_run_date date11.;
format last_run_date mmddyy10.;
datalines;
9-sep-2018 08:04:54
9-sep-2018 08:01:41
9-sep-2018 07:01:28
9-sep-2018 05:06:23
9-sep-2018 05:06:21
31-oct-2017 14:56:35
31-oct-2017 11:08:46
31-oct-2017 10:17:21
31-may-2015 00:01:11
31-mar-2018 12:25:20
;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.