Obsidian | Level 7

## setting variable for a specific day/date each month

I am tasked with developing a report that will run daily.  There are 11 error checks,  for 9 of 11 error checks I need to report daily.

The problems is that 2 of the error checks are monthly and only need to run 1 time each month around the 2nd business day.

Is there any way to create a variable that will set to 1 if it is the second business day of the month?

Or maybe if it is easier the 2nd Tuesday of the month?

2 REPLIES 2

## Re: setting variable for a specific day/date each month

You can calculate the second Tuesday as follows.  For the 2nd business day you will need to define business day.  Check out Holiday function and or custom date intervals.

data _null_;

do y=2015 to 2016;

do m=1 to 12;

do d = 1,10,20,28;
today=mdy(m,d,y);

'2ndTues'n = intnx('week.3',intnx('month',today,0,'B'),2,'B');
put (today '2'n🙂 (=weekdate.);
end;

put;

end;

end;

run;

today=Thursday, January
1, 2015 2ndTues=Tuesday, January 13, 2015
today=Saturday, January
10, 2015 2ndTues=Tuesday, January 13, 2015
today=Tuesday, January
20, 2015 2ndTues=Tuesday, January 13, 2015
today=Wednesday, January
28, 2015 2ndTues=Tuesday, January 13, 2015

today=Sunday, February
1, 2015 2ndTues=Tuesday, February 10, 2015
today=Tuesday, February
10, 2015 2ndTues=Tuesday, February 10, 2015
today=Friday, February
20, 2015 2ndTues=Tuesday, February 10, 2015
today=Saturday, February
28, 2015 2ndTues=Tuesday, February 10, 2015

today=Sunday, March
1, 2015 2ndTues=Tuesday, March 10, 2015
today=Tuesday, March
10, 2015 2ndTues=Tuesday, March 10, 2015
today=Friday, March
20, 2015 2ndTues=Tuesday, March 10, 2015
today=Saturday, March
28, 2015 2ndTues=Tuesday, March 10, 2015

today=Wednesday, April
1, 2015 2ndTues=Tuesday, April 14, 2015
today=Friday, April
10, 2015 2ndTues=Tuesday, April 14, 2015
today=Monday, April
20, 2015 2ndTues=Tuesday, April 14, 2015
today=Tuesday, April
28, 2015 2ndTues=Tuesday, April 14, 2015
Super User

## Re: setting variable for a specific day/date each month

data _null_;

date = today();

year = year(date);

int_date = intnx('month',date,0,'begin');

count = 0;

do until (int_date > date);

if

weekday(int_date) not in (1,7) and

int_date ne holiday('easter',year) + 1 /* easter monday */ and

int_date ne holiday('easter',year) + 50 /* pentecost monday */ and

int_date ne mdy(1,1,year) and

int_date ne mdy(7,4,year)

/* treat additional holidays as required */

then count = count + 1;

int_date = int_date + 1;

end;

call symput('num_workdays',strip(put(count,best.)));

run;

Now you can use &num_workdays as the number of business days in the month.

Discussion stats
• 2 replies
• 658 views
• 0 likes
• 3 in conversation