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
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
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
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!
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.
Ready to level-up your skills? Choose your own adventure.