<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dutra</title>
    <description>The latest articles on DEV Community by Dutra (@vanhurter).</description>
    <link>https://dev.to/vanhurter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1084741%2Fad7cca16-026b-4a79-8beb-9d9796c0db1a.jpeg</url>
      <title>DEV Community: Dutra</title>
      <link>https://dev.to/vanhurter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vanhurter"/>
    <language>en</language>
    <item>
      <title>SAS Function setDateByNumberBDays</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Thu, 18 May 2023 23:56:54 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-function-setdatebynumberbdays-i3m</link>
      <guid>https://dev.to/vanhurter/sas-function-setdatebynumberbdays-i3m</guid>
      <description>&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
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 &amp;lt; abs(numberDays));
            if numberDays &amp;gt; 0 then
                date = date + 1;
            else
                date = date - 1;

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

        return(date);
    endsub;



quit;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sas</category>
      <category>sql</category>
      <category>proc</category>
    </item>
    <item>
      <title>SAS Function isBrHolidayworkingDaysBetweenDates</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Thu, 18 May 2023 23:31:02 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-function-isbrholidayworkingdaysbetweendates-35pa</link>
      <guid>https://dev.to/vanhurter/sas-function-isbrholidayworkingdaysbetweendates-35pa</guid>
      <description>&lt;p&gt;The function returns the number of working days between two given dates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;proc fcmp outlib=work.sas_functions.dateFunctions;

    /*
    =================== 
     * FUNCTION:workingDaysBetweenDates
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Returns the number of working days 
     between two given dates
    ===================
    */
    function workingDaysBetweenDates(startDate, endDate);
        numberDays = 0;
        addData = startDate;

        if startDate &amp;lt;= endDate then;
        do while (addData &amp;lt;= endDate);
            if isBusinessDay(addData) &amp;lt;&amp;gt; 0 then
                numberDays = numberDays + 1;
            addData = intnx('day',addData,1);
        end;

        return(numberDays);
    endsub;

quit;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sas</category>
      <category>sql</category>
      <category>proc</category>
    </item>
    <item>
      <title>SAS Functions extras for previous or next dates</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Thu, 18 May 2023 23:20:41 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-functions-extras-for-previous-or-next-dates-ji8</link>
      <guid>https://dev.to/vanhurter/sas-functions-extras-for-previous-or-next-dates-ji8</guid>
      <description>&lt;p&gt;As auxiliary functions of &lt;strong&gt;isBusinessDay&lt;/strong&gt;, &lt;strong&gt;previousBusinessDay&lt;/strong&gt;and &lt;strong&gt;nextBusinessDay&lt;/strong&gt;, the functions &lt;strong&gt;ifNonBDayPreviousBDay&lt;/strong&gt; and &lt;strong&gt;ifNonBDayNextBDay&lt;/strong&gt; test whether the informed date is a business day, if not, it returns the previous or subsequent business day date, respectively to each function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>SAS Functions previous and next BusinessDay</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Thu, 18 May 2023 22:52:57 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-functions-previous-and-next-businessday-6p</link>
      <guid>https://dev.to/vanhurter/sas-functions-previous-and-next-businessday-6p</guid>
      <description>&lt;p&gt;The functions with the aid of the previous functions of &lt;strong&gt;isBusinessDay&lt;/strong&gt; and &lt;strong&gt;isBrHoliday&lt;/strong&gt; return the previous or next useful date of an initial date informed in the parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sas</category>
      <category>sql</category>
      <category>datefunctions</category>
      <category>proc</category>
    </item>
    <item>
      <title>SAS Function isBusinessDay</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Thu, 18 May 2023 00:29:45 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-function-isbusinessday-1c9k</link>
      <guid>https://dev.to/vanhurter/sas-function-isbusinessday-1c9k</guid>
      <description>&lt;p&gt;This is an auxiliary function to &lt;strong&gt;isBrHoliday&lt;/strong&gt;, 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 &lt;strong&gt;proc fcmp&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sas</category>
      <category>sql</category>
      <category>datefunctions</category>
      <category>proc</category>
    </item>
    <item>
      <title>SAS Function isBrHoliday</title>
      <dc:creator>Dutra</dc:creator>
      <pubDate>Wed, 17 May 2023 23:55:42 +0000</pubDate>
      <link>https://dev.to/vanhurter/sas-function-isbrholiday-22p4</link>
      <guid>https://dev.to/vanhurter/sas-function-isbrholiday-22p4</guid>
      <description>&lt;p&gt;A useful function to test if a date is a Brazilian national holiday. With the necessary adaptations, it can be used for other countries, applying their respective holidays. The function uses &lt;strong&gt;proc fcmp&lt;/strong&gt; to work with executions in a different way than the construction of macros, for this purpose the created functions are stored in a specific library in the &lt;strong&gt;outlib&lt;/strong&gt; parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;proc fcmp outlib=work.sas_functions.dateFunctions;

    /*
    =================== 
     * FUNCTION:isBrHoliday
     * AUTHOR: Dutra - dutra@relevants.org
     * DESCRIPTION: Tests a date to validate if it is a 
Brazilian national holiday, returning 0 or 1.
    ===================
    */
    function isBrHoliday(date);
        year                = year(date);
        anonovo             = mdy(01,01,year);
        tiradentes          = mdy(04,21,year);
        diaTrabalho         = mdy(05,01,year);
        independencia       = mdy(09,07,year);
        nsraAparecida       = mdy(10,12,year);
        finados             = mdy(11,02,year);
        republica           = mdy(11,15,year);
        natal               = mdy(12,25,year);
        pascoa              = holiday('easter', year);
        segCarnaval         = pascoa - 48;
        terCarnaval         = pascoa - 47;
        sextaPaixao         = pascoa - 2;
        corpusChristi       = pascoa + 60;

        if date in (anonovo, segCarnaval, terCarnaval,
 sextaPaixao, pascoa, corpusChristi, tiradentes, diaTrabalho,
 independencia, nsraAparecida, finados, republica, natal
               ) then
            return(1);
        else 
            return(0);
    endsub;

quit;

options cmplib=work.sas_functions; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use the function just call passing the date parameter. As in the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; /*
Function test, defining the date and passing it as a parameter of
the isHoliday function
*/
%let date=%sysfunc(mdy(12,25,2023));

%let isHoliday=%sysfunc(isBrHoliday(&amp;amp;date.));

%put Date=&amp;amp;date. - isHoliday=&amp;amp;isHoliday.;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope it can help with your projects. I will also make new posts available about other functions that I use to handle dates.&lt;/p&gt;

</description>
      <category>sas</category>
      <category>sql</category>
      <category>datefunctions</category>
      <category>procfcmp</category>
    </item>
  </channel>
</rss>
