I have a dataset that has the following columns:
Year - Numerical - 2021
Date - Character - 07/03
I am attempting to get a numerical day_skey that takes the two columns and creates the following:
day_skey - 20210703
Any tips on how to get my desired date field?
If you don't want to see the log "NOTE: Character values have been converted to numeric values at the places given by: " one of several ways:
data _null_; year = 2021; date = '07/03'; dt = Input(catx('/',date,year),mmddyy10.); put dt = yymmddn8.; run;
Use the MDY function and the yymmddn8. format.
data _null_;
year = 2021;
date = '07/03';
dt = mdy(scan(date, 1, '/'), scan(date, 2, '/'), year);
put dt = yymmddn8.;
run;
If you don't want to see the log "NOTE: Character values have been converted to numeric values at the places given by: " one of several ways:
data _null_; year = 2021; date = '07/03'; dt = Input(catx('/',date,year),mmddyy10.); put dt = yymmddn8.; run;
I tried both options but am still getting the same result for the day_skey
Thanks for your response. I've tried doing your example, but am getting the following for the desired date field:
These are valid SAS date values (count of days starting at 1960-01-01), but you need to assign a date format to make them human-readable:
format day_skey yymmdd10.;
Thank you all! I just needed to format that date, it wasn't working with the put statement for some reason.
The PUT state results appear in the LOG (or if you have a FILE statement in the named file).
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.