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

Top comments (0)