BookmarkSubscribeRSS Feed
PierreYvesILY
Pyrite | Level 9

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?

 

3 REPLIES 3
Kurt_Bremser
Super User

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().

Kurt_Bremser
Super User

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
;
PierreYvesILY
Pyrite | Level 9
Hello Kurt,

thank you for your Suggestion. I could use it to built my solution.

Have a nice evening.
Regards