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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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