Help using Base SAS procedures

Week Function, Changing the value of the descriptor

New Contributor
Posts: 2

Week Function, Changing the value of the descriptor

Given the syntax of  WEEK(<sas-date>, <'descriptor'>) for the week function and "U" being Sunday as first day of week and "W" being Monday as first day of week, is it possible to change these or create a custom descriptor to set the start of the week to Saturday?  I have a report that I am creating where currently it reports stats on a weekly basis starting on Sunday and running through Saturday.  The recipient of the report would like the report to run from Saturday and end on Friday.

Super User
Posts: 10,516

Re: Week Function, Changing the value of the descriptor

Quick and dirty I would create a new variable using the date shifted by one day.

MyWeek= week((sasdate-1));

New Contributor
Posts: 2

Re: Week Function, Changing the value of the descriptor

I found this in a white paper online, initial testing appears to be working for shifting the start of the week for the date ranges.


The quickest way to group weeks with a start date other than Sunday is by using Shift Operators

with the INTNX function. If you recall the first parameter specified in the INTNX function is the

interval. Multipliers and shift indexes can be used with the basic interval names to construct more

complex intervals. When using multipliers and shift indexes your interval name will have the

format: NAMEm.s

NAME    is the basic interval time. In our case, it would be WEEK

m           is an optional multiplier which multiplies the interval by the specified value. For

example, the interval WEEK2 consists of two-week periods.

S           is an optional starting point for the interval. By default, the WEEK interval starts on

Sunday with Sunday=1. So if you want a week to start on Wednesday (value =4) then the interval

would be WEEK.4 .

Both the multipliers and shift index are optional and default to 1. So the intervals,

WEEK,WEEK1.1,WEEK.1 are all equivalent to the basic week interval. Different intervals are shifted

by different subperiods. For our purposes, week is shifted by days. Also the shift index cannot be

greater than the number of subperiods in the whole interval (so no greater than 7).

For example, let’s take our last3weeks dataset but define the weeks to start on Thursdays:

DATA last3weeks; SET last3weeks;

start = intnx('week.5',trans_date,0,'beginning'); end = intnx('week.5',trans_date,0,'end');

ThuWeeks = catx(' - ', PUT(start2,mmddyy8.),put(end2,mmddyy8.));


Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation