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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: