BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5

## How to determine the week of the year and change the start of the week from Sunday to Friday

Hello,

I have SAS date for various events and for each observation I want to determine which week of the year the event happen. However, i want that the week would start on Friday, not Sunday. How can i do this?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Jade | Level 19

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

Again:

``````data want;
set your_dataset;
week=intck('week.6', intnx('year', your_sasdatevar, 0), your_sasdatevar)+1;
run;``````
9 REPLIES 9
Diamond | Level 26

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

You need to use the INTCK function. You can specify what day of the week the function should start from, in your case Friday.

--
Paige Miller
PROC Star

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

If January 1 is a Thursday, do you want the first week of the year to contain just a single day?  Then January 2 through January 8 would be week 2?

Calcite | Level 5

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

yes, for example in 2018 1 week would be from 1 January till 4 January, second from 5 to 8 and so on...

I looked at INTCK function, however i need to give start and end dates, but I have a variable and i do not  want to look what time period it consists every time i use it.

Jade | Level 19

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

Hi @viollete,

Try this:

``````data have;
input d yymmdd8.;
format d weekdatx.;
cards;
20151231
20160101
20171228
20171229
20171231
20180101
20180104
20180105
20180907
;

data want;
set have;
wk=intck('week.6', intnx('year',d,0), d)+1;
run;

proc print data=want;
run;``````
Super User

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

@viollete wrote:

yes, for example in 2018 1 week would be from 1 January till 4 January, second from 5 to 8 and so on...

I looked at INTCK function, however i need to give start and end dates, but I have a variable and i do not  want to look what time period it consists every time i use it.

One hopes that you meant the second week is 5 to 11 or we have another issue involved.

Again I ask, HOW are your intending to use this? On what duration of data? Please provide an explicit example of some date values and how you are using "Friday starting week". It likely isn't very difficult but without knowing if what you want is shift for the WEEK function, using a variation of one of the WEEKU, WEEKV or WEEKW formats, or something else it is very difficult to provide an actual solution to a-not-well-defined problem.

Diamond | Level 26

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

INTCK

start date is '01JAN18'd

end date is the date variable value

This gives you the number of weeks since January 1, 2018, and when you do it properly, it counts weeks starting on Friday

--
Paige Miller
Super User

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

@viollete wrote:

Hello,

I have SAS date for various events and for each observation I want to determine which week of the year the event happen. However, i want that the week would start on Friday, not Sunday. How can i do this?

Thank you

You should provide some example of how this start of week on Friday is going to be used.

For example read the documentation on the WEEK function and the uses of the U, V and W descriptors on determining week number of year values returned to see some things that may need to be considered for your specific usage. For instance what if Friday is in a different calendar year? Is it still the start of your week?

Calcite | Level 5

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

I have at least 10 years period and over several millions observation. For each year, I want to find in which week the observation happened. So each year will have 1-52/53 weeks.

if sas date is between 1st January 2018 and 4th January, week=1, if between 5th January 2018 and 11th then week=2

if sa date is between 1st January 2017 and 5th January, week=1, if between 6th January 2017 and 12th then week=2

and so on...

Jade | Level 19

## Re: How to determine the week of the year and change the start of the week from Sunday to Friday

Again:

``````data want;
set your_dataset;
week=intck('week.6', intnx('year', your_sasdatevar, 0), your_sasdatevar)+1;
run;``````
Discussion stats
• 9 replies
• 2811 views
• 0 likes
• 5 in conversation