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

We have a scheduled task running each Monday morning setting start and stop date to the dates of the previous week, week starting Mondays

For example when running on 4'th January 2021 it sets the start and stop date to 28Dec2020 and 03 Jan2021 as follows:

%LET STARTDATE = %sysfunc(intnx(DAY,(%sysfunc(intnx(WEEK,(%SYSFUNC(today(),)),-1,b),)),+1),date9.);
%PUT &STARTDATE;
%LET STOPDATE = %sysfunc(intnx(DAY,(%sysfunc(intnx(WEEK,(%SYSFUNC(today(),)),-1,e),)),+1),date9.);
%PUT &STOPDATE;

We set another macro variable to the corresponding week number

With this year 2020/2021 we don't seem to be able to get the week number right (=53)  using the intnx function ...

%LET WEEK = %sysfunc(intnx(WEEK,(%SYSFUNC(today(),)),0),weeku3.);

Please suggest solution which would set the week number for running on 04Jan2021 to '53' and on 11Jan2021 to '01'

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @PerBundgaard  Are you looking to do this?

%LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),-1)),v));
%put &=week;
14         %LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),-1)),v));
15         %put &=week;
WEEK=53

And likewise, for current week, setting the increment to 0-

14         %LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),0)),v));
15         %put &=week;
WEEK=1

 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @PerBundgaard  Are you looking to do this?

%LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),-1)),v));
%put &=week;
14         %LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),-1)),v));
15         %put &=week;
WEEK=53

And likewise, for current week, setting the increment to 0-

14         %LET WEEK=%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),0)),v));
15         %put &=week;
WEEK=1

 

PerBundgaard
Obsidian | Level 7
Ahh, OK, the ‘v’ descriptor and the week function on top 😊
%LET WEEK = ;
%LET WEEK=W%sysfunc(week(%sysfunc(intnx(WEEK,'04Jan2021'D,0)),v));
%put &=week;

Thanks a lot !
PerBundgaard
Obsidian | Level 7
Ended up with this solution, including leading zeros, Thanks again !
%LET WEEK=W%sysfunc(week(%sysfunc(intnx(WEEK,%SYSFUNC(today()),0)),v),z2.);
%put &=week;
WEEK=W01

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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