<?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: Macro for the do-loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743466#M232785</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/365042"&gt;@saweheh&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your 28 day increment intended to be one month?&amp;nbsp; I assume it is.&amp;nbsp; You might want to use the "sameday" option of function INTNX which will be a lot more precise.&amp;nbsp; I've written a macro to just that which I will include below.&amp;nbsp; I've written another macro to write the results to the log.&amp;nbsp; In the log, we can see that I'm incrementing a full month each time, regardless of whether a month is 28, 29, 30, or 31 days long.&amp;nbsp; Such is the power of INTNX.&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	Start_Date	=	'01JAN2021'd;

**------------------------------------------------------------------------------**;

%MACRO	Months_Loop(Start_Date, Nbr_of_Months=20);
	%LOCAL	i  j  Temp_Date;
	%GLOBAL	M0;

	%LET	M0					=	%QSYSFUNC(STRIP(%QSYSFUNC(PUTN(&amp;amp;Start_Date, 9.))));

	%DO		i					=	1	%TO	&amp;amp;Nbr_Of_Months;
		%GLOBAL	M&amp;amp;i;
		%LET	j				=	%EVAL(&amp;amp;i - 1);
		%LET	M&amp;amp;i	=	%QSYSFUNC(INTNX(month,&amp;amp;&amp;amp;M&amp;amp;j,1,sameday));
	%END;
%MEND	Months_Loop;

%Months_Loop(&amp;amp;Start_Date);

**------------------------------------------------------------------------------**;

%MACRO	Display_Months(Nbr_of_Months=20);
	%LOCAL	i;
	%LOCAL	Formatted_Date;

	%DO		i					=	0	%TO	&amp;amp;Nbr_of_Months;
		%LET	Formatted_Date	=	%QSYSFUNC(PUTN(&amp;amp;&amp;amp;M&amp;amp;i, DATE9.));
		%PUT	NOTE:  Month &amp;amp;i =	&amp;amp;&amp;amp;M&amp;amp;i (&amp;amp;Formatted_Date);
	%END;
%MEND	Display_Months;

%Display_Months;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;NOTE:  Month 0 = 22281 (01JAN2021)
NOTE:  Month 1 = 22312 (01FEB2021)
NOTE:  Month 2 = 22340 (01MAR2021)
NOTE:  Month 3 = 22371 (01APR2021)
NOTE:  Month 4 = 22401 (01MAY2021)
NOTE:  Month 5 = 22432 (01JUN2021)
NOTE:  Month 6 = 22462 (01JUL2021)
NOTE:  Month 7 = 22493 (01AUG2021)
NOTE:  Month 8 = 22524 (01SEP2021)
NOTE:  Month 9 = 22554 (01OCT2021)
NOTE:  Month 10 = 22585 (01NOV2021)
NOTE:  Month 11 = 22615 (01DEC2021)
NOTE:  Month 12 = 22646 (01JAN2022)
NOTE:  Month 13 = 22677 (01FEB2022)
NOTE:  Month 14 = 22705 (01MAR2022)
NOTE:  Month 15 = 22736 (01APR2022)
NOTE:  Month 16 = 22766 (01MAY2022)
NOTE:  Month 17 = 22797 (01JUN2022)
NOTE:  Month 18 = 22827 (01JUL2022)
NOTE:  Month 19 = 22858 (01AUG2022)
NOTE:  Month 20 = 22889 (01SEP2022)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2021 04:06:23 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-05-25T04:06:23Z</dc:date>
    <item>
      <title>Macro for the do-loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743451#M232778</link>
      <description>&lt;P&gt;Can someone help write a macro do loop for the following scenario, please? Rather than doing it manually line-by-line, it would be great if this can be done using a macro. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Let M0=Start_Date+28;&lt;BR /&gt;%Let M1=Start_Date+56;&lt;BR /&gt;%Let M2=Start_Date+84;&lt;BR /&gt;%Let M3=Start_Date+112;&lt;BR /&gt;%Let M4=Start_Date+140;&lt;BR /&gt;%Let M5=Start_Date+168;&lt;BR /&gt;%Let M6=Start_Date+196;&lt;BR /&gt;%Let M7=Start_Date+224;&lt;BR /&gt;%Let M8=Start_Date+252;&lt;BR /&gt;%Let M9=Start_Date+280;&lt;BR /&gt;%Let M10=Start_Date+308;&lt;BR /&gt;%Let M11=Start_Date+336;&lt;BR /&gt;%Let M12=Start_Date+364;&lt;BR /&gt;%Let M13=Start_Date+392;&lt;BR /&gt;%Let M14=Start_Date+420;&lt;BR /&gt;%Let M15=Start_Date+448;&lt;BR /&gt;%Let M16=Start_Date+476;&lt;BR /&gt;%Let M17=Start_Date+504;&lt;BR /&gt;%Let M18=Start_Date+532;&lt;BR /&gt;%Let M19=Start_Date+560;&lt;BR /&gt;%Let M20=Start_Date+588;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 01:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743451#M232778</guid>
      <dc:creator>saweheh</dc:creator>
      <dc:date>2021-05-25T01:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for the do-loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743461#M232783</link>
      <description>&lt;P&gt;While I'm not certain that the result you describe is the result that you want, it is relatively straightforward to produce:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop28;
   %local i;
   %do i=0 %to 20;
      %global m&amp;amp;i;
      %let m&amp;amp;i = Start_Date+%eval(28 + 28*&amp;amp;i);
   %end;
%mend loop28;
%loop28&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 May 2021 02:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743461#M232783</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-05-25T02:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for the do-loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743466#M232785</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/365042"&gt;@saweheh&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your 28 day increment intended to be one month?&amp;nbsp; I assume it is.&amp;nbsp; You might want to use the "sameday" option of function INTNX which will be a lot more precise.&amp;nbsp; I've written a macro to just that which I will include below.&amp;nbsp; I've written another macro to write the results to the log.&amp;nbsp; In the log, we can see that I'm incrementing a full month each time, regardless of whether a month is 28, 29, 30, or 31 days long.&amp;nbsp; Such is the power of INTNX.&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	Start_Date	=	'01JAN2021'd;

**------------------------------------------------------------------------------**;

%MACRO	Months_Loop(Start_Date, Nbr_of_Months=20);
	%LOCAL	i  j  Temp_Date;
	%GLOBAL	M0;

	%LET	M0					=	%QSYSFUNC(STRIP(%QSYSFUNC(PUTN(&amp;amp;Start_Date, 9.))));

	%DO		i					=	1	%TO	&amp;amp;Nbr_Of_Months;
		%GLOBAL	M&amp;amp;i;
		%LET	j				=	%EVAL(&amp;amp;i - 1);
		%LET	M&amp;amp;i	=	%QSYSFUNC(INTNX(month,&amp;amp;&amp;amp;M&amp;amp;j,1,sameday));
	%END;
%MEND	Months_Loop;

%Months_Loop(&amp;amp;Start_Date);

**------------------------------------------------------------------------------**;

%MACRO	Display_Months(Nbr_of_Months=20);
	%LOCAL	i;
	%LOCAL	Formatted_Date;

	%DO		i					=	0	%TO	&amp;amp;Nbr_of_Months;
		%LET	Formatted_Date	=	%QSYSFUNC(PUTN(&amp;amp;&amp;amp;M&amp;amp;i, DATE9.));
		%PUT	NOTE:  Month &amp;amp;i =	&amp;amp;&amp;amp;M&amp;amp;i (&amp;amp;Formatted_Date);
	%END;
%MEND	Display_Months;

%Display_Months;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;NOTE:  Month 0 = 22281 (01JAN2021)
NOTE:  Month 1 = 22312 (01FEB2021)
NOTE:  Month 2 = 22340 (01MAR2021)
NOTE:  Month 3 = 22371 (01APR2021)
NOTE:  Month 4 = 22401 (01MAY2021)
NOTE:  Month 5 = 22432 (01JUN2021)
NOTE:  Month 6 = 22462 (01JUL2021)
NOTE:  Month 7 = 22493 (01AUG2021)
NOTE:  Month 8 = 22524 (01SEP2021)
NOTE:  Month 9 = 22554 (01OCT2021)
NOTE:  Month 10 = 22585 (01NOV2021)
NOTE:  Month 11 = 22615 (01DEC2021)
NOTE:  Month 12 = 22646 (01JAN2022)
NOTE:  Month 13 = 22677 (01FEB2022)
NOTE:  Month 14 = 22705 (01MAR2022)
NOTE:  Month 15 = 22736 (01APR2022)
NOTE:  Month 16 = 22766 (01MAY2022)
NOTE:  Month 17 = 22797 (01JUN2022)
NOTE:  Month 18 = 22827 (01JUL2022)
NOTE:  Month 19 = 22858 (01AUG2022)
NOTE:  Month 20 = 22889 (01SEP2022)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 04:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743466#M232785</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-05-25T04:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for the do-loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743490#M232796</link>
      <description>&lt;P&gt;Thank you so much. This is exactly what I need.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 06:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-the-do-loop/m-p/743490#M232796</guid>
      <dc:creator>saweheh</dc:creator>
      <dc:date>2021-05-25T06:41:44Z</dc:date>
    </item>
  </channel>
</rss>

