BookmarkSubscribeRSS Feed
DougJ
Calcite | Level 5

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.


2 REPLIES 2
ballardw
Super User

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

MyWeek= week((sasdate-1));

DougJ
Calcite | Level 5

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.

http://www.pharmasug.org/proceedings/2012/CC/PharmaSUG-2012-CC19.pdf

NON-TRADITIONAL WEEKS

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

RUN;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2445 views
  • 3 likes
  • 2 in conversation