DEV Community

Dutra
Dutra

Posted on

1 1

SAS Functions extras for previous or next dates

As auxiliary functions of isBusinessDay, previousBusinessDayand nextBusinessDay, the functions ifNonBDayPreviousBDay and ifNonBDayNextBDay test whether the informed date is a business day, if not, it returns the previous or subsequent business day date, respectively to each function.

proc fcmp outlib=work.sas_functions.dateFunctions;

    /*
    =================== 
     * FUNCTION:ifNonBDayPreviousBDay
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Checks if the given date is a working day, 
     otherwise returns the previous working day date
    ===================
    */
    function ifNonBDayPreviousBDay(date);
        if isBusinessDay(date) = 0 then
            return(previousBusinessDay(date));
        else return(date);
    endsub;

    /*
    =================== 
     * FUNCTION:ifNonBDayNextBDay
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Checks if the given date is a working day, 
     otherwise returns the next working day date
    ===================
    */

    function ifNonBDayNextBDay(date);
        if isBusinessDay(date) = 0 then
            return(nextBusinessDay(date));
        else return(date);
    endsub;

quit;
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay