if year="2024" then do;
wk1=(compress('wk'||put(week(date) + 1,z2.)));
wk2=compress(substr(year,3,2)||'_'||wk1);
end;
What does the "+1" mean? I thought it was to add an additional week but 2024 has 52 weeks. Or maybe this is just copy and pasted wrong in my program.
How many other "years" have this conditional code?
Look in the online documentation for the WEEK function and the U, V and W modifiers. This may have been a similar adjustment to the weeks in a given year based on the starting day and/or leap day adjustments by someone that doesn't know other tools exist.
Anyone dealing with character year values already has one strike against them as far as I am concerned when in comes to thinking the code is "good".
The +1
in the week definition is indeed meant to add an additional week to the current week number. This is typically used to create a label or identifier for the next week, as in the example wk36
when the current week is wk35
.
However, since 2024 has 52 weeks, adding 1 to the last week of the year (week 52
) would result in week 53
, which might not be valid depending on how your system or application handles week numbers. If week(date)
returns 52 and you add 1, it might result in an invalid week number, leading to potential issues.
If the +1
is not intentional (e.g., if you don't actually need to reference the next week), it might indeed be a copy-paste mistake. You could consider removing the +1
if your intention is to use the current week number without incrementing it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.