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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 585 views
  • 2 likes
  • 2 in conversation