BookmarkSubscribeRSS Feed
stancemcgraw
Obsidian | Level 7

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

4 REPLIES 4
ballardw
Super User

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.

stancemcgraw
Obsidian | Level 7

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

FreelanceReinh
Jade | Level 19

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

SASKiwi
PROC Star

There are recognised international standards defining week numbers. The SAS WEEK function can provide some of these: 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=ds2ref&docsetTarget=n09mp...

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 688 views
  • 0 likes
  • 4 in conversation