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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 390 views
  • 2 likes
  • 2 in conversation