I have week, month, and year variables and need to create a date variable from these. Suggestions on how to do this?
Aligns to the beginning of the week;
date=mdy(1,1,year)+(week-1)*7;
OR
intnx('week', mdy(1,1, year), week, 'middle');
And look at the alignment options for intnx function, ie beginning end, middle.
How does your week look, it is 25 indicating 25th week of the year or 2 indicating the 2nd week of a month?
Assuming its between 1 and 5
something like the following may work:
date=mdy(month, 7*(week-1)+1 , year);
It is numbered 0 through 52, so 25 indicates the 25th week of the year.
Would you like the date to reflect any specific day of the week?
Thursdays preferably, but if it is too difficult that way it doesn't particularly matter that much.
Weeks can cross months so having a specific day may not be possible
Even just an approximate day would be ok.
e.g.
wk 1 = 1/1/14
wk 2 = 1/8/14
wk 3 = 1/15/14
etc.
Aligns to the beginning of the week;
date=mdy(1,1,year)+(week-1)*7;
OR
intnx('week', mdy(1,1, year), week, 'middle');
And look at the alignment options for intnx function, ie beginning end, middle.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.