Here's something I found while straying from the point of a recent question.
Given a SAS date, how can one compute the first and last weekdays of the
month in which it falls? Here's what I devised:
keep mm first last ;
format mm monyy7. first last weekdate.;
do y = 1998 to 2007; do m = 1 to 12;
mm = mdy(m,15,y);
last = intnx('weekday',intnx('month',mm, 0,'e'),0);
The formula for LAST is not too messy. The inner INTNX call provides the
last day of the month, and the outer INTNX call shifts a Saturday or Sunday
to the preceding Friday.
I cannot see a way to symmetrically implement that logic to find the first
weekday. That's because WEEKDAY intervals merge weekend days with the
*preceding* non-weekend day. So the formula I devised finds the last weekday
of the previous month, then utilizes yet another INTNX call to advance that
to the next weekday (being the first weekday of the given month). So it ends
up with three nested INTNX calls. Is there a better (more concise) way?