Hello.
I am trying to create a variable from data in a data set with dates. When using the intnx('weekday'...) function, if the previous weekday was in the month/year prior to the beginning of the month I am looking for, it goes back to that date. I am trying to figure out a way to either just leave it at the first of the month if it is on the weekend or take it forward to the first weekday. For instance, January 1st 2022 was on Saturday. Using the weekday function pulls December 31st even when indicating the month should be at the beginning. How can I handle this?
proc sql;
select intnx('weekday',intnx('month',max(date1),-2,'b'),0)
into :last2monthbegindate
from table 1
where name in ('name1','name2','name2')
;
quit;
The result of this query above is 12/31/2021 instead of 1/1/2022 (or 1/3/2022, the first weekday in January). If adjusting the code to look back to February, it gives the desired results because February 1 was a weekday.
... View more