dear SAS experts,
I must select data over several weeks and over the end of the year.
In the table, I have a column JAHR (year) and a column KW (week), as in the attached file.
In the week 1 (KW = 1), I Need to select the green selection.
In the week 1 (KW = 4), I Need to select the yellow selection.
In the week 1 (KW = 5), I Need to select the red selection.
How could I proceed?
So you need to find, from a given week, the previous 5 weeks?
Anyway, since you have date-related values, you should store them as SAS dates and use the appropriate display format; then it would be subtraction of 7 or INTNX().
I see it's 4 weeks. See this code to illustrate the usefulness of SAS date values:
data want;
input year week;
format
currdate yymmdd10.
date weekv7.
;
currdate = input(cats(put(year,z4.),'W',put(week,z2.)),weekv7.);
do date = currdate - 28 to currdate - 1 by 7;
output;
end;
datalines;
2021 1
2021 4
2021 5
;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.