This is ugly, but it works. I assumed that you are just working with 2011, but it is expandable. I created an informat HOLIDAY that returns 1 if the date is a holiday or 0 if not.
proc format ;
invalue holiday '01JAN2011'd,'25JAN2011'd,
'23DEC2011'd,'25DEC2011'd,
'26DEC2011'd = 1
other=0;
run;
data dates2011; /* generate test dates for 2011 */
do date = '01JAN2011'd to '31DEC2011'd;
output;
format date date9.;
end;
run;
data dates2011a;
set dates2011;
busday_2before = date-2;
xloop = 0;
LOOP:;
xweekday = weekday(busday_2before);
xloop = xloop+1;
if xloop > 5 then stop;
if xweekday in (1,7) then do;
if xweekday = 1 then busday_2before = busday_2before-2;
else busday_2before = busday_2before-1;
end;
if input(put(busday_2before,5.),holiday.) then do;
busday_2before = busday_2before-1;
goto loop; /* make sure not Saturday, sunday, or holiday, again */
end;
format busday_2before date9.;
run;
... View more