BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sas_noob25
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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;

 

ballardw
Super User

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;
Sas_noob25
Obsidian | Level 7

I tried both options but am still getting the same result for the day_skey

 

Sas_noob25_0-1645127683305.png

Sas_noob25
Obsidian | Level 7

Thanks for your response. I've tried doing your example, but am getting the following for the desired date field:

 

Sas_noob25_0-1645127683305.png

 

Kurt_Bremser
Super User

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.;
Sas_noob25
Obsidian | Level 7

Thank you all! I just needed to format that date, it wasn't working with the put statement for some reason. 

 

ballardw
Super User

The PUT state results appear in the LOG (or if you have a FILE statement in the named file).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

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
  • 7 replies
  • 1903 views
  • 1 like
  • 4 in conversation