BookmarkSubscribeRSS Feed
Elliott
Obsidian | Level 7

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?

Thanks in advance.

2 REPLIES 2
data_null__
Jade | Level 19

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
Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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