<?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: how to add 45day intervals for 1 year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688386#M209103</link>
    <description>&lt;P&gt;If it's it's a set period you need the 45 day incrdments for, you could do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
    period1dt='08OCT2019'd;&lt;BR /&gt;&lt;BR /&gt;    day45_1=intnx('day',period1dt,45);
    day45_2=intnx('day',day45_1,45);
    day45_3=intnx('day',day45_2,45);
    day45_4=intnx('day',day45_3,45);
    day45_5=intnx('day',day45_4,45);
    day45_6=intnx('day',day45_5,45);
    day45_7=intnx('day',day45_6,45);
    day45_8=intnx('day',day45_7,45);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2020 22:32:40 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2020-10-01T22:32:40Z</dc:date>
    <item>
      <title>how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688383#M209101</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I add 45days from from a year ago to today's date?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is what i have so far in my program but it is only adding 45days for 08OCT2019 (period 2).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create period 3, period 4, period 5, etc. until present day. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
    period1dt='08OCT2019'd;
    day45=intnx('day',period1dt,45);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 22:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688383#M209101</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-10-01T22:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688386#M209103</link>
      <description>&lt;P&gt;If it's it's a set period you need the 45 day incrdments for, you could do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
    period1dt='08OCT2019'd;&lt;BR /&gt;&lt;BR /&gt;    day45_1=intnx('day',period1dt,45);
    day45_2=intnx('day',day45_1,45);
    day45_3=intnx('day',day45_2,45);
    day45_4=intnx('day',day45_3,45);
    day45_5=intnx('day',day45_4,45);
    day45_6=intnx('day',day45_5,45);
    day45_7=intnx('day',day45_6,45);
    day45_8=intnx('day',day45_7,45);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 22:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688386#M209103</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T22:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688388#M209104</link>
      <description>&lt;P&gt;Results from the above (with formats added for clarity):&lt;/P&gt;
&lt;DIV id="tinyMceEditorjimbarbour_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601591854634.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50092iE426EE3E1D438E73/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601591854634.png" alt="jimbarbour_0-1601591854634.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 22:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688388#M209104</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T22:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688392#M209106</link>
      <description>is there a way to make the program more efficient?</description>
      <pubDate>Thu, 01 Oct 2020 22:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688392#M209106</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-10-01T22:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688393#M209107</link>
      <description>&lt;P&gt;And if you want it as rows and a little less hardcoded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
    format period1dt date10.;
    period1dt='08OCT2019'd;    
    do until(period1dt &amp;gt; date());
      output;
      period1dt = intnx('day',period1dt,45);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 22:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688393#M209107</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-10-01T22:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688394#M209108</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;is there a way to make the program more efficient?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Define efficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An array and loop counter for the number of times you want to add 45 days would be one way.&lt;/P&gt;
&lt;P&gt;But since 45 does not go evenly into a year, 8.11111 (repeats) when the year is 365 days or 8.13333 (repeats) when 366 days, then your definition for "intervals for 1 year" needs some expansion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 22:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688394#M209108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-01T22:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688398#M209112</link>
      <description>&lt;P&gt;Perhaps you are looking for something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data have;
    startdt='08OCT2019'd; output;
    startdt='08DEC2019'd; output;
    startdt='08DEC2017'd; output;
  run;

  data x;
      set have;
      array period [1:100] ;
      i = 1;
      period1dt = startdt;
      do until(period1dt &amp;gt; date() or i &amp;gt; 100);
        period(i) = period1dt;
        period1dt = intnx('day',period1dt,45);
        i = i + 1;
      end;
  run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 23:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688398#M209112</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-10-01T23:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to add 45day intervals for 1 year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688400#M209113</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean efficient or do you mean flexible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make it so there is little hard coding and the program is very flexible, you could use macros like the below example.&amp;nbsp; Here, even the variable names in the output SAS dataset are dynamically determined based on the values of the macro variables set at the top of the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results from the below program:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601593971592.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50093iF76B4242B6A72A21/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1601593971592.png" alt="jimbarbour_0-1601593971592.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Period_Start	=	'08OCT2019'd;
%LET	Period_End		=	%QSYSFUNC(INTNX(DAY,&amp;amp;Period_Start, 365));
%LET	Increment		=	45;

%MACRO	Calculate_Periods;
	%DO	i	=	1	%TO	999;
		%GLOBAL	Day45_&amp;amp;i;
		%GLOBAL	Nbr_Increments;
		%IF	%SYSFUNC(INTNX(DAY,&amp;amp;Period_Start, %EVAL(&amp;amp;Increment * &amp;amp;i)))	&amp;gt;	&amp;amp;Period_End	%THEN
			%DO;
				%LET	Nbr_Increments	=	%EVAL(&amp;amp;i - 1);
				%LET	i				=	999;
			%END;
		%ELSE
			%DO;
				%LET	Day&amp;amp;Increment._&amp;amp;i		=	%SYSFUNC(INTNX(DAY,&amp;amp;Period_Start, %EVAL(&amp;amp;Increment * &amp;amp;i)));
			%END;
	%END;
%MEND	Calculate_Periods;

%Calculate_Periods;
*%PUT	_USER_;

%MACRO	Generate_SAS_Code;
	%DO	i					=	1	%TO	&amp;amp;Nbr_Increments;
		Day&amp;amp;Increment._&amp;amp;i	=	&amp;amp;&amp;amp;Day&amp;amp;Increment._&amp;amp;i;
	%END;
%MEND	Generate_SAS_Code;

data x;
	FORMAT	Period_Start Day&amp;amp;Increment._1 - Day&amp;amp;Increment._&amp;amp;Nbr_Increments Period_End YYMMDDD10.;
	Period_Start	=	&amp;amp;Period_Start;
	Period_End		=	&amp;amp;Period_End;
	%Generate_SAS_Code;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 23:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-45day-intervals-for-1-year/m-p/688400#M209113</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T23:13:07Z</dc:date>
    </item>
  </channel>
</rss>

