Hello,
I have dates that start on 3.16.19 and run through 5.31.19, and I'd like to identify the week numbers, starting with 3.16 as 1 all the way through 10. It's currently starting my weeks as 10, as in the 10th week of 2019 and since 3/16 is a Saturday, it's starting week 11 starting on 3/17. I'd like:
data have:
week10=3/16/20-3/21/20.
week11=3/17-3/23
data want:
week1:3/16-3/23
week2: 3/24-3/30
3/16 (week1)-3/23; 3/24;
week2: 3/24-3/30
3/16 (week1)-3/23; 3/24;
week2: 3/24-3/30
3/16 x3/23; 3/24;
week2: 3/24-3/30
So just what code are you currently using to get "week" values?
If you know how many "weeks" something should be from a base date you should be able to get that using the INTCK and INTNX functions. I can't provide any code as you haven't said exactly when your week one should start and possibly which day of the week should be the first of the new week.
I was initially using the week function as:
WEEK=WEEK(date of arrival), but my date range includes 3/16/20-5/31/20, so that function outputs this:
data have:
week date of arrival
10 3/16/2019
11 3/17/2019
11 3/22/2019
12 3/24/2019
data want:
week date of arrival
1 3/16/2019
1 3/17/2019
1 3/22/2019
2 3/24/2019
Hello @stancemcgraw,
Try this:
week=ceil((date-'15MAR2019'd)/7);
Equivalently (for your date range) you can use the INTCK function (with the shifted interval 'week.7' -- weeks starting on Saturdays), as suggested by ballardw:
week=intck('week.7','15MAR2019'd, date);
Or the WEEK function, as suggested by SASKiwi:
week=week(date-69);
The "magic" number 69 can be computed as '16MAR2019'd-nwkdom(1,1,1,2019), i.e., the difference (in days) between the first day of week 1 in your date range and the first day of week 1 of 2019 according to the WEEK function (with the default "descriptor").
There are recognised international standards defining week numbers. The SAS WEEK function can provide some of these:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.