<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Date Increment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780893#M248867</link>
    <description>&lt;P&gt;Assuming your pattern will keep repeating, something like this will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Input data */;
DATA INPUT;
    INFILE DATALINES;
    INPUT MODEL $10.;
    DATALINES;
735
736
737
777
775
772
773
787
797
747
;
RUN;

/* Define your work days (code from: https://communities.sas.com/t5/SAS-Programming/macro-to-exclude-week-end-days-and-company-holidays-from-the/td-p/356141) */
data wrkdays (keep=begin);
  format begin date9.;
  array holidays(6);
  do date = '16nov2021'd to '31dec2030'd ;  **UPDATE with your date range;
    if date eq intnx('year',date,0,'b') then do;
      call missing(of holidays(*));
      i=0;
    end;
    if date eq holiday('NEWYEAR', year(date)) or
       date eq holiday('USINDEPENDENCE',year(date)) or
       date eq holiday('THANKSGIVING', year(date)) or
       date eq holiday('CHRISTMAS', year(date)) or
       date eq holiday('MEMORIAL', year(date)) or
       date eq holiday('LABOR', year(date)) then do; **UPDATE with Holidays you want to exclude;
      i+1;
      holidays(i)=date;
    end;
    if not(date in holidays or weekday(date) in (1,7)) then do;
      season=1;
      begin=date;
      output;
    end;
  end;
run;

/* Generate final data */
options intervalds=(workdays=wrkdays); **define date interval for INTNX function;
data want (drop = counter);
    set input;
    
    counter + 1; **start a counter;
    if counter = 7 then counter = 1; **reset the counter every 7th row, pattern restarts here;
      
    retain Build_Date; 
    if _n_ = 1 then Build_Date = "16nov2021"d ; **first row should be 11/16/2021. Use today() if you want date of submit;
    else if counter ne 2 then Build_Date = intnx('workdays', Build_Date, 1); **repeats previous date on counter = 2 and adds 1 work day otherwise, excludes weekends;
    
    format Build_Date mmddyy10.;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last row (model 747) here will have 11/26/2021 instead of 11/25/2021 which is Thanksgiving Day.&amp;nbsp;You'll need to modify the wrkdays data set to include the Holidays you wish to exclude.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 22:23:38 GMT</pubDate>
    <dc:creator>lopezr</dc:creator>
    <dc:date>2021-11-17T22:23:38Z</dc:date>
    <item>
      <title>Date Increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780759#M248795</link>
      <description>&lt;P&gt;Hi, please help me to write a code for the below request.&lt;/P&gt;
&lt;P&gt;For first two model Build_Date will be today's date and for next four model Build_date is incremented by 1, it has to follow same sequence for next 6 models. The Build_Date&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should exclude weekends and the list of Holidays we provide.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Input */;
DATA INPUT;
INFILE DATALINES;
INPUT MODEL $10.;
DATALINES;
735
736
737
777
775
772
773
787
797
747
;&lt;BR /&gt;RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Expected Output:&lt;/P&gt;
&lt;P&gt;Model Build_Date&lt;/P&gt;
&lt;P&gt;735&amp;nbsp; &amp;nbsp; 11/16/2021&lt;/P&gt;
&lt;P&gt;736&amp;nbsp; &amp;nbsp; 11/16/2021&lt;/P&gt;
&lt;P&gt;737&amp;nbsp; &amp;nbsp; 11/17/2021&lt;/P&gt;
&lt;P&gt;777&amp;nbsp; &amp;nbsp; 11/18/2021&lt;/P&gt;
&lt;P&gt;775&amp;nbsp; &amp;nbsp; 11/19/2021&lt;/P&gt;
&lt;P&gt;772&amp;nbsp; &amp;nbsp; 11/22/2021&lt;/P&gt;
&lt;P&gt;773&amp;nbsp; &amp;nbsp; 11/23/2021&lt;/P&gt;
&lt;P&gt;787&amp;nbsp; &amp;nbsp; 11/23/2021&lt;/P&gt;
&lt;P&gt;797&amp;nbsp; &amp;nbsp; 11/24/2021&lt;/P&gt;
&lt;P&gt;747&amp;nbsp; &amp;nbsp; 11/25/2021&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 15:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780759#M248795</guid>
      <dc:creator>vidyasagar1</dc:creator>
      <dc:date>2021-11-17T15:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date Increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780893#M248867</link>
      <description>&lt;P&gt;Assuming your pattern will keep repeating, something like this will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Input data */;
DATA INPUT;
    INFILE DATALINES;
    INPUT MODEL $10.;
    DATALINES;
735
736
737
777
775
772
773
787
797
747
;
RUN;

/* Define your work days (code from: https://communities.sas.com/t5/SAS-Programming/macro-to-exclude-week-end-days-and-company-holidays-from-the/td-p/356141) */
data wrkdays (keep=begin);
  format begin date9.;
  array holidays(6);
  do date = '16nov2021'd to '31dec2030'd ;  **UPDATE with your date range;
    if date eq intnx('year',date,0,'b') then do;
      call missing(of holidays(*));
      i=0;
    end;
    if date eq holiday('NEWYEAR', year(date)) or
       date eq holiday('USINDEPENDENCE',year(date)) or
       date eq holiday('THANKSGIVING', year(date)) or
       date eq holiday('CHRISTMAS', year(date)) or
       date eq holiday('MEMORIAL', year(date)) or
       date eq holiday('LABOR', year(date)) then do; **UPDATE with Holidays you want to exclude;
      i+1;
      holidays(i)=date;
    end;
    if not(date in holidays or weekday(date) in (1,7)) then do;
      season=1;
      begin=date;
      output;
    end;
  end;
run;

/* Generate final data */
options intervalds=(workdays=wrkdays); **define date interval for INTNX function;
data want (drop = counter);
    set input;
    
    counter + 1; **start a counter;
    if counter = 7 then counter = 1; **reset the counter every 7th row, pattern restarts here;
      
    retain Build_Date; 
    if _n_ = 1 then Build_Date = "16nov2021"d ; **first row should be 11/16/2021. Use today() if you want date of submit;
    else if counter ne 2 then Build_Date = intnx('workdays', Build_Date, 1); **repeats previous date on counter = 2 and adds 1 work day otherwise, excludes weekends;
    
    format Build_Date mmddyy10.;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last row (model 747) here will have 11/26/2021 instead of 11/25/2021 which is Thanksgiving Day.&amp;nbsp;You'll need to modify the wrkdays data set to include the Holidays you wish to exclude.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 22:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780893#M248867</guid>
      <dc:creator>lopezr</dc:creator>
      <dc:date>2021-11-17T22:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Date Increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780922#M248872</link>
      <description>&lt;P&gt;Apparently the models in rows 2 and 8 will have the same date value as the immediately preceding row.&amp;nbsp; But every row except those at 2 modulo 6 should have date incremented by 1, skipping holidays and weekends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using US holidays, you can use the HOLIDAY functions as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52346"&gt;@lopezr&lt;/a&gt;&amp;nbsp;.&amp;nbsp; &amp;nbsp;You can put those dates in a hash object.&amp;nbsp; Then just keep incrementing the date (except for row 2) until the new date is a weekday and is not in the hash object:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  input model $10.;
  retain date ;
  format date weekdate22. ;
  if _n_=1 then do;
    *populate holidays hash object, keyed on DATE;
    declare hash holidays();
       holidays.definekey('date');
       holidays.definedata('date');
       holidays.definedone();
    do _year=2021 to 2022;
      do _holiday_name='USINDEPENDENCE','NEWYEAR','THANKSGIVING','CHRISTMAS','MEMORIAL','LABOR';
        date=holiday(_holiday_name,_year);
        holidays.add();
      end;
    end;

    *initialize date to precede first model (assume first model will be TODAY() ) **;
    date=today()-1;
  end;

  if mod(_n_,6)^=2 then do date=date+1 by 1 until (holidays.check()^=0  and weekday(date) in (2,3,4,5,6)) ; end;
datalines;
735
736
737
777
775
772
773
787
797
747
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Nov 2021 01:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/780922#M248872</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-11-18T01:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date Increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/781002#M248903</link>
      <description>&lt;P&gt;Looks the like the problem you have posted some time ago: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Incrementing-the-dates/m-p/780750" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Incrementing-the-dates/m-p/780750&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Nov 2021 12:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Increment/m-p/781002#M248903</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-18T12:31:25Z</dc:date>
    </item>
  </channel>
</rss>

