Is there a SAS function which returns the month based on the week identifier?
Ex.: Week 26 => 06
or Week 26 => JUNE
Hello @PierreYvesILY,
You could pick one of the WEEK... informats and use the MONTH, INPUT, CATS and PUT functions to compute the month from week number and year.
Example:
data test;
do week=26 to 27;
do year=2019 to 2021;
mon=month(input(cats(year,'W',put(week,z2.)),weekv.));
output;
end;
end;
run;
Result:
week year mon 26 2019 6 26 2020 6 26 2021 6 27 2019 7 27 2020 6 27 2021 7
In this example the month is (by default) calculated for the Monday of the respective week.
Not that I know of.
Since a week can be split between two months, you need to figure how you want to map this.
So I think that you need to go via a date first.
I believe what you're asking for is not possible without also knowing the year AND the logic used to determine the first day of week 1.
For below found here: https://www.epochconverter.com/weeks/2020
Without a year what month should week 1 get - and what month week 52 or 53?
Hello @PierreYvesILY,
You could pick one of the WEEK... informats and use the MONTH, INPUT, CATS and PUT functions to compute the month from week number and year.
Example:
data test;
do week=26 to 27;
do year=2019 to 2021;
mon=month(input(cats(year,'W',put(week,z2.)),weekv.));
output;
end;
end;
run;
Result:
week year mon 26 2019 6 26 2020 6 26 2021 6 27 2019 7 27 2020 6 27 2021 7
In this example the month is (by default) calculated for the Monday of the respective week.
hey Reinhard,
thanks a lot for this very good solution, which is exactly what I was looking for!
I just modified my program with it and tested it, it's just perfect.
Have a nice WE
Regards,
PY
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.