data lastworkdays;
do year=2005 to 2015;
do m=1 to 12;
date1= mdy(m,1,year) ;
date2=intnx('month',date1,0,'end')
-((weekday(intnx('month',date1,0,'end'))=1)*2)
-((weekday(intnx('month',date1,0,'end'))=7)*1);
weekday2=weekday(date2);
cnt=0;
do i=date2 to date2-5 by -1;
weekday=weekday( i);
if weekday in (2,3,4,5,6) then do;
cnt+1;
if cnt <=3 then output;
end;
end;
cnt=0;
do i=date2+1 to date2+5 by 1;
weekday=weekday( i);
if weekday in (2,3,4,5,6) then do;
cnt+1;
if cnt <=2 then output;
end;
end;
end;
end;
rename i= lastworkdays;
run;
proc sort data= lastworkdays; by lastworkdays; run;
proc sql noprint;
select lastworkdays into: list separated by ', '
from lastworkdays;
quit;
proc format;
value lastworkdays
&list =1
other=0;
run;
***verify**;
data _null_;
do i='20aug2010'd to '11dec2010'd;
put i= date9. i= lastworkdays.;
end;
run;