DEV Community

Dutra
Dutra

Posted on

1 1

SAS Function setDateByNumberBDays

This function defines a new date by calculating it, starting from the informed one plus the number of working days provided as parameters. When using negative days, it returns previous dates.


proc fcmp outlib=work.sas_functions.dateFunctions;

    /*
    =================== 
     * FUNCTION:setDateByNumberBDays
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Defines a new date by calculating the 
     number of working days provided as a parameter. 
     When using negative days it returns previous dates.
    ===================
    */
    function setDateByNumberBDays(date, numberDays);

        numberBDays = 0;

        do while (numberBDays < abs(numberDays));
            if numberDays > 0 then
                date = date + 1;
            else
                date = date - 1;

            if isBusinessDay(date) then
                numberBDays = numberBDays + 1;
        end;

        return(date);
    endsub;



quit;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

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

Okay