Hello, Happy New Year to All!
I wanted to ask assistance in adjusting the below code, I'm trying to get Weekdates for 2024 that ends in Tuesdays.
below is the code I am using and I am not getting the first week of this year which is 01/02/2024, can someone look into it? thanks a lot.
*Report uses Tuesday's EOD inventory; data WeekDates; *Preparing a list of holidays that land on a Tuesday and a list of Mondays to use in lieu of; if _N_ = 0 then do; %let HOLIDAYS =; %let PROXY_DAYS =; array STAT_HOLIDAY[4] $9. _temporary_ ('newyear', 'canada', 'christmas', 'boxing'); do YEAR=&BEGIN_YEAR to &END_YEAR; do i=1 to 4; if weekday(holiday(STAT_HOLIDAY[i],YEAR)) = 3 then do; call symputx('HOLIDAYS',catx(', ',resolve('&HOLIDAYS'),"'"||put(holiday(STAT_HOLIDAY[i],YEAR),mmddyy10.)||"'")); call symputx('PROXY_DAYS',catx(', ',resolve('&PROXY_DAYS'),"'"||put(intnx('day',holiday(STAT_HOLIDAY[i],YEAR),-1),mmddyy10.)||"'")); end; end; end; end;
*Check if the first day of the year is in the same week as any dates in the previous year. If so, SAS will treat this week as week zero, so bump the week up by 1 to accommodate; if week(intnx('week',intnx('year',mdy(1,1,&END_YEAR),0),0)+2) = 1 then do i=0 to 52; /*** changed from =0 to =1 to reflect first week of 2023 ***/ WEEK=i+1; do j=1 to 4; *Check if the PORTFOLIO_WEEK will be a holiday, which will cause dips in the data due to stores being closed; if holiday(STAT_HOLIDAY[j],&END_YEAR) = intnx('week',mdy(1,1,&END_YEAR),i)+2 then do; *If Tuesday is a holiday, use the previous day, i.e. Monday's EOD inventory instead; PORTFOLIO_WEEK = intnx('week',mdy(1,1,&END_YEAR),i)+1; *Leave the DO loop as soon as there is a TRUE condition, otherwise it could overwrite on the subsequent iteration; leave; end; else PORTFOLIO_WEEK = intnx('week',mdy(1,1,&END_YEAR),i)+2; end; output; end; else do i=1 to 52; WEEK=i; do j=1 to 4; if holiday(STAT_HOLIDAY[j],&END_YEAR) = intnx('week',mdy(1,1,&END_YEAR),i)+2 then do; PORTFOLIO_WEEK = intnx('week',mdy(1,1,&END_YEAR),i)+1; leave; end; else PORTFOLIO_WEEK = intnx('week',mdy(1,1,&END_YEAR),i)+2; end; output; end; format PORTFOLIO_WEEK mmddyy10.;
drop i j year; run;
... View more