How can I use different sets of date values depending on the date

123 views Asked by At

I am looking to automate a daily report for my company but I have run in to a bit of trouble. The report gets updated only on the 2nd working day of each month. I found some code on the SAS website which works out what the 2nd working day of any month is.

data scdwrk;
  /* advance date to the first day of the month using the INTNX function */
  second=intnx('month',today(),0);
  /* determine the day of the week using the WEEKDAY function */
  day=weekday(second);
  /* if day=Monday then advance by 1 */
  if day=2 then second+1;
  /* if day=Sunday then advance by 2 */
  else if day=1 then second+2;
  format second date9.;
run ; 

I have also set a flag that compares todays date to the date from this generated by this piece of code. I now need to find a way that if the code is run on the first working day of the month then it runs a particular set of macro date variables

%let start_date="&prevmnth;
%let end_date= &endprevmnth;
%let month= &prevyearmnth; 

and then when its run on the 2nd working day of the month it uses the other set of macro date variables (calender month)

%let start_date="&currmnth;
%let end_date= &endcurrmnth;
%let month= &curryearmnth;

Any help on this would be greatly appreciated.

1

There are 1 answers

1
DomPazz On

I have some recent code that does just this. Here is how I tackled it.

First, create a table of holidays. This can be maintained yearly.

Second, create a table with the first 5 days of the month that are not weekend days.

Third, delete holidays.

Finally, get the second value in the data set.

data holidays;
format holiday_date date9.;
informat holiday_date date9.;
input holiday_date;
datalines;
01JAN2015
19JAn2015
16FEB2015
03APR2015
25MAY2015
03JUL2015
07SEP2015
26NOV2015
25DEC2015
;

data _dates;
firstday = intnx('month',today(),0);
format firstday date date9.;
do date=firstday to firstday+5;
    if 1 < weekday(date) < 7 then
        output;
end;
run;

proc sql noprint;
delete from _dates
where date in (select holiday_date from holidays);

quit;

data _null_;
set _dates(firstobs=2);
call symput("secondWorkDay",put(date,date9.));
stop;
run;

%put &secondWorkDay;