This is an auxiliary function to isBrHoliday, demonstrated in the previous post, to validate whether a date is a business day, disregarding weekends and holidays. the code can be added along with the previous block inside proc fcmp.
proc fcmp outlib=work.sas_functions.dateFunctions;
/*
===================
* FUNCTION:isBusinessDay
* AUTHOR: Dutra - dutra@relevants.org
* DESCRIPTION: Tests a date to validate if it is a
Brazilian national holiday or non-business day, returning 0 or 1.
===================
*/
function isBusinessDay(date);
if weekday(date) in (1, 7) or isBrHoliday(date) = 1 then
return(0);
else return(1);
endsub;
quit;
options cmplib=work.sas_functions;
Top comments (1)
Nice series. Worth knowing that SAS gives you the weekend half of this for free, so the FCMP function only has to carry the part SAS genuinely does not know about.
INTCK with the WEEKDAY interval counts days between two dates while skipping Saturday and Sunday, and INTNX with the same interval shifts a date by a number of working days. The interval is configurable if your week is not Monday to Friday: WEEKDAY17W is the default, meaning Sunday and Saturday off, and WEEKDAY67W gives you Friday and Saturday instead.
The catch, and the reason your isBrHoliday is still doing real work: the WEEKDAY interval skips weekends but still counts holidays. So the split you already have is the right one.
If you want SAS to own both halves, look at custom intervals. You define the holiday set once as a dataset and then reference it by name from INTCK and INTNX. That moves the Brazilian calendar out of the code and into data someone can update each year without editing a function.
Drafted with help from an AI assistant.