DEV Community

Dutra
Dutra

Posted on

SAS Functions previous and next BusinessDay

The functions with the aid of the previous functions of isBusinessDay and isBrHoliday return the previous or next useful date of an initial date informed in the parameter.

proc fcmp outlib=work.sas_functions.dateFunctions;

    /*
    =================== 
     * FUNCTION:previousBusinessDay
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Returns the previous working day of a 
       given date
    ===================
    */
    function previousBusinessDay(date);
        previousDay = intnx('day',date,-1);

        do while (isBusinessDay(previousDay) = 0);
            previousDay = intnx('day', previousDay, -1);
        end;

        return(previousDay);
    endsub;

    /*
    =================== 
     * FUNCTION:nextBusinessDay
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Returns the next working day of a given date
    ===================
    */

    function nextBusinessDay(date);
        nextDay = intnx('day',date,1);

        do while (isBusinessDay(nextDay) = 0);
            nextDay = intnx('day', nextDay, 1);
        end;

        return(nextDay);
    endsub;


quit;

options cmplib=work.sas_functions;
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay