<?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: Dynamic Macro Loop -  To Create An Automatic Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280605#M56725</link>
    <description>&lt;P&gt;You probably want to adjust the number of periods to handle the situation you have presented with using a start date that is not the end of the month. &amp;nbsp;For example try this program. &amp;nbsp;I added some values before and after the interval defined by startdate to enddate and added a IF statement to set those to PERIOD=0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  attrib date informat=date9. format=date9. ;
  input date @@ ;
cards;
01MAY2010 31MAY2010 01JUN2010 30JUN2010 01JUL2010 01AUG2010
01SEP2010 01OCT2010 01NOV2010 01DEC2010 01JAN2011 01FEB2011
01MAR2011 01APR2011 01MAY2011 01JUN2011 01JUL2011 01AUG2011
01SEP2011 01OCT2011 01NOV2011 01DEC2011 01JAN2012 01FEB2012
01MAR2012 01APR2012 01MAY2012 01JUN2012 01JUL2012 01AUG2012
01SEP2012 01OCT2012 01NOV2012 01DEC2012 01JAN2013 01FEB2013
01MAR2013 01APR2013 01MAY2013 01JUN2013 01JUL2013 01AUG2013
01SEP2013 01OCT2013 01NOV2013 01DEC2013 01JAN2014 01FEB2014
01MAR2014 01APR2014 01MAY2014 01JUN2014 01JUL2014 01AUG2014
01SEP2014 01OCT2014 31OCT2014 01NOV2014 30NOV2014 01DEC2014
31DEC2014 01JAN2015 01FEB2015 01MAR2015 31MAR2015 01APR2015
;
%let startdate=01jun2010;
%let enddate=31mar2015;
%let startdate2 = %sysfunc(intnx(month,"&amp;amp;startdate"d,0,b))-1;
%let startdate2 = %sysfunc(putn(&amp;amp;startdate2,date9));
%let nperiods=%sysfunc(ceil(%sysfunc(intck(month,"&amp;amp;startdate2"d,"&amp;amp;enddate"d))/3));
%put &amp;amp;=nperiods;

data want;
  set have;
  if date &amp;lt; "&amp;amp;startdate"d or date &amp;gt; "&amp;amp;enddate"d then period=0;
  else period = &amp;amp;nperiods - int(intck('month',date,"&amp;amp;enddate"d)/3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To see the results by period you could run this little data _null_ step since the input was sorted by DATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set want ;
  by period notsorted;
  if first.period then put / period= z2. +1 @;
  put date @ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Whch produces this list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period=00  01MAY2010 31MAY2010
period=01  01JUN2010 30JUN2010
period=02  01JUL2010 01AUG2010 01SEP2010
period=03  01OCT2010 01NOV2010 01DEC2010
period=04  01JAN2011 01FEB2011 01MAR2011
period=05  01APR2011 01MAY2011 01JUN2011
period=06  01JUL2011 01AUG2011 01SEP2011
period=07  01OCT2011 01NOV2011 01DEC2011
period=08  01JAN2012 01FEB2012 01MAR2012
period=09  01APR2012 01MAY2012 01JUN2012
period=10  01JUL2012 01AUG2012 01SEP2012
period=11  01OCT2012 01NOV2012 01DEC2012
period=12  01JAN2013 01FEB2013 01MAR2013
period=13  01APR2013 01MAY2013 01JUN2013
period=14  01JUL2013 01AUG2013 01SEP2013
period=15  01OCT2013 01NOV2013 01DEC2013
period=16  01JAN2014 01FEB2014 01MAR2014
period=17  01APR2014 01MAY2014 01JUN2014
period=18  01JUL2014 01AUG2014 01SEP2014
period=19  01OCT2014 31OCT2014 01NOV2014 30NOV2014 01DEC2014 31DEC2014
period=20  01JAN2015 01FEB2015 01MAR2015 31MAR2015
period=00  01APR2015&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jun 2016 22:18:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-06-27T22:18:12Z</dc:date>
    <item>
      <title>Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278479#M56024</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question which is little bit complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a sample data set which includes dates, I need to determine these dates periods. I have a sample code as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Format Pro_End_Date_Ym DATE9.;
Infile Datalines Missover;
Input Pro_End_Date_Ym;
Datalines;
10826
10827
10828
10829
10830
10850
10870
10880
10991
10999
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Months start with EndDate and decreasing three by three but when it comes StartDate it needs to catch up the excess between EndDate and StartDate. I mean first period months can increase one by one. If you can investigate my following code, you can understand better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Purpose*/
%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;
/*Purpose*/&lt;BR /&gt;&lt;BR /&gt;
Data Want;
Set Have;
Length Period 4.; 
Period = 0;
if '31JUL1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '31AUG1989'd then Period = 1;/*Decreasing 1 month&lt;BR /&gt;because it cannot excess the StartDate*/
if '31AUG1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '30NOV1989'd then Period = 2;/*Decreasing 3 months*/
if '30NOV1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '28FEB1990'd then Period = 3;/*Decreasing 3 months*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My purpose is just define the StartDate and EndDate and create the dates and Periods automatically. Actually, I need to create dates and periods being macro variables. But it seems to me it cannot possible for us. I just want to give your opinions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The foregoing data step gives my desired output, but I want to take them dynamically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&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>Sun, 19 Jun 2016 15:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278479#M56024</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-19T15:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278496#M56026</link>
      <description>&lt;P&gt;It's definitely possible. Use intnx to increment dates, make sure to look at the last parameter that aligns the dates to beginning or end of month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 17:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278496#M56026</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T17:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278532#M56039</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for reminder, the following is going to provide me the my desired dynamic loop, however, I have some questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why this statement doesn't work -&amp;gt;&amp;nbsp;%Let FormattedDate=%Sysfunc(Intnx('Month',"&amp;amp;LatestDate."D,0,"E")); and the following code seems okay but I'm not sure, also seems little bit extended, are there any short methods?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;
/*Hold variable in the Macro variable*/
Proc Sql;
Select Pro_End_Date_Ym Into:Dates Separated By " " From Have
Order By Pro_End_Date_Ym Desc;
Quit;

%Let Count=%Sysfunc(CountW(&amp;amp;Dates));/*Count of Dates*/
%Let LatestDate=%Scan(&amp;amp;Dates,-1);/*Hold latest Value to use in further steps*/
%Let FormattedDate=%Sysfunc(Intnx('Month',"&amp;amp;LatestDate."D,0,"E")); /*Why it doesn't work???*/
%Put &amp;amp;Dates;
%Put &amp;amp;Count;
%Put &amp;amp;LatestDate;
%Put &amp;amp;FormattedDate;
/*Convert values to latest day of month*/
%Macro Months(Month);
Data Want2(Drop=Pro_End_Date_Ym);
Set Have;
		%Do i=1 %To &amp;amp;Count.;
		%Let Var&amp;amp;i = %Scan(&amp;amp;Dates,&amp;amp;i,%str( ));
			Months=Intnx('Month',"&amp;amp;&amp;amp;Var&amp;amp;i"D,0,"E"); Output; Format Months Date9.;
		%End;
Run;
%Mend Months;
%Months; /*Why it brings 100 row instead of 10*/
/*Hold converted values in the Macro variable*/
Proc Sql;
Select Distinct Months Into:Dates2 Separated By " " From Want2
Order By Months Asc;
Quit;
%Let Count2=%Sysfunc(CountW(&amp;amp;Dates2));/*Count of Dates2*/
%Put &amp;amp;Dates2;
%Put &amp;amp;Count2;
%Macro Months2(Month2);
Data Want;
Set Have;
Length Period 4.; 
Period = 0;
%If &amp;amp;Count GT 0 %Then %Do;
	%Do j = &amp;amp;Count %To 1 %By -1;
	%Let Var&amp;amp;j = %Scan(&amp;amp;Dates2,&amp;amp;j,%Str( ));
If Intnx('Month',"&amp;amp;&amp;amp;Var&amp;amp;j."D,-3,"E")&amp;lt; PRO_END_DATE_YM &amp;lt;=Intnx('Month',"&amp;amp;&amp;amp;Var&amp;amp;j."D,0,"E")Then Period = &amp;amp;j; 
    %End;
	%IF PRO_END_DATE_YM &amp;lt;=&amp;amp;LatestDate. %Then %Do;
	If Intnx('Month',"&amp;amp;StartDate."D,-3,"E")&amp;lt; PRO_END_DATE_YM &amp;lt;=Intnx('Month',"&amp;amp;LatestDate."D,0,"E")Then Period = &amp;amp;j; 
%End;
%End;
Run;
%Mend Months2;
%Months2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jun 2016 21:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278532#M56039</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-19T21:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278542#M56042</link>
      <description>&lt;P&gt;Wow. I don't think you need that much macro logic...start with your first macro, months. You get 100 results because you loop 10 times over each record. I think you only need the data step and no macro logic there. Try simplifying that as a starter.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 22:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278542#M56042</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T22:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278547#M56043</link>
      <description>&lt;P&gt;You don't quote parameters in %sysfunc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe post what you want your output to be and we can help you get there without all of that macro logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Let FormattedDate=%Sysfunc(Intnx(Month,"&amp;amp;LatestDate."D,0,E));&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 22:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278547#M56043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T22:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278552#M56047</link>
      <description>&lt;P&gt;What are you actually trying to do? &amp;nbsp;Hard to tell but it looks like you are just dividing a time interval into periods and calculating for the dates in your dataset which period it falls into? &amp;nbsp;Why not just do that directly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have a variable DATE (perhaps your&amp;nbsp;PRO_END_DATE_YM variable) and you want see how many months it is away from the START date then use the INTCK() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=31JUL1989 ;

data want ;
  set have ;
  month_num = intck('month',"&amp;amp;start"d,DATE);
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 22:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278552#M56047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-19T22:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278553#M56048</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;. Additionally, you may be able to use SAS QTR to calculate some of these and you don't need to create custom intervals depending on your requirements.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 23:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278553#M56048</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T23:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278605#M56061</link>
      <description>&lt;P&gt;Hello &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your explanations, I'm going to try to explain what I am trying to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, the following code creates my desired output&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;Data Want;
Set Have;
Length Period 4.; 
Period = 0;
if '31JUL1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '31AUG1989'd then Period = 1;&lt;BR /&gt;/*Decreasing 1 month because it cannot excess the StartDate*/
if '31AUG1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '30NOV1989'd then Period = 2;&lt;BR /&gt;/*Decreasing 3 months*/
if '30NOV1989'd &amp;lt; PRO_END_DATE_YM &amp;lt;= '28FEB1990'd then Period = 3;&lt;BR /&gt;/*Decreasing 3 months*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create this structure being dynamic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But these date values for e example-&amp;gt;"28FEB1990", &amp;nbsp;"30NOV1989", "31AUG1989" are decreasing three by three but it doesn't mean it represents quarters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the customer is going to write Start and End Date as parametric -&amp;gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%Let&lt;/SPAN&gt; StartDate&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;31&lt;/SPAN&gt;JUL1989&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macroname"&gt;%Let&lt;/SPAN&gt; EndDate&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;28&lt;/SPAN&gt;FEB1990&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But in my foregoing example when it comes "31AUG1989" there is just one month between "31AUG1989" and StartDate("31JUL1989") so it shouldn't decrease three months it should decrease just one month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My purpose is that get Start and End Date then create the Data Want which I wrote in my foregoing Data Step. I would like to remind that this is a sample data, the data will have more observations in real environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a summary, I just determine the Start and End Date the it will create dates and periods&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For Example -&amp;gt;"28FEB1990", &amp;nbsp;"30NOV1989", "31AUG1989" and for Periods -&amp;gt; 1, 2 and 3 will automatically.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Something like this&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;
Data Want;
Set Have;
Length Period 4.; 
Period = 0;
if "&amp;amp;Macro2"d &amp;lt; PRO_END_DATE_YM &amp;lt;= "&amp;amp;Macro2"d then Period = &amp;amp;Macro2;
/*Decreasing 1 month because it cannot excess the StartDate*/
if "&amp;amp;Macro2"d  &amp;lt; PRO_END_DATE_YM &amp;lt;= "&amp;amp;Macro2"d then Period = &amp;amp;Macro2;
/*Decreasing 3 months*/
if "&amp;amp;Macro2"d &amp;lt; PRO_END_DATE_YM &amp;lt;= "&amp;amp;Macro2"d then Period = &amp;amp;Macro2;
/*Decreasing 3 months*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Actually the following Months2 macro helps me but as you realize before this macro I did many steps&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Months2(Month2);
Data Want;
Set Have;
Length Period 4.; 
Period = 0;
%If &amp;amp;Count GT 0 %Then %Do;
	%Do j = &amp;amp;Count %To 1 %By -1;
	%Let Var&amp;amp;j = %Scan(&amp;amp;Dates2,&amp;amp;j,%Str( ));
If Intnx('Month',"&amp;amp;&amp;amp;Var&amp;amp;j."D,-3,"E")&amp;lt; PRO_END_DATE_YM &amp;lt;=Intnx('Month',"&amp;amp;&amp;amp;Var&amp;amp;j."D,0,"E")Then Period = &amp;amp;j; 
    %End;
	%IF PRO_END_DATE_YM &amp;lt;=&amp;amp;LatestDate. %Then %Do;
	If Intnx('Month',"&amp;amp;StartDate."D,0,"E")&amp;lt; PRO_END_DATE_YM &amp;lt;=Intnx('Month',"&amp;amp;LatestDate."D,0,"E")Then Period = &amp;amp;j; 
%End;
%End;
Run;
%Mend Months2;
%Months2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 08:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278605#M56061</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-20T08:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278633#M56066</link>
      <description>&lt;P&gt;Why is the first one only one month, not three like the others? That's the key logic that needs to be captured.&lt;/P&gt;
&lt;P&gt;Besides that, it's relatively easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;

Data Want;
sest have;
Length Period 4.; 
Period = 0;

boundary1 = "&amp;amp;startDate"d;
boundary2 = intnx("month", "&amp;amp;startDate"d, 1, 'e');
boundary3 = intnx("month", "&amp;amp;startDate"d, 4, 'e');
boundary4 = intnx("month", "&amp;amp;startDate"d, 7, 'e');

format boundary: date9.;

if boundary1 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary2 then Period = 1;/*Decreasing 1 month because it cannot excess the StartDate*/
if boundary2 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary3 then Period = 2;/*Decreasing 3 months*/
if boundary3 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary4 then Period = 3;/*Decreasing 3 months*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jun 2016 10:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278633#M56066</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-20T10:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278851#M56135</link>
      <description>&lt;P&gt;Hello again,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for preparing a code but Start Date and End Date can change and Periods also depends on the Start Date and End Date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to create this structere for Macro variables, I mean StartDate and EndDate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I mean is that what if End Date is "31AUG1990" instead of &amp;nbsp;"28FEB1990", Periods also will change for Start Date and End Date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be happy, If I get some direction from you. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 22:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278851#M56135</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-20T22:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278863#M56136</link>
      <description>The dates will change but rules have to stay the same. Whether its a macro or non macro solution this is true. So what are your rules.</description>
      <pubDate>Mon, 20 Jun 2016 22:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278863#M56136</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-20T22:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278865#M56138</link>
      <description>&lt;P&gt;Sorry&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;English is not my mother language, I guess that is the reason why I cannot explain myself clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I prepared your code then I delivered the code to the customer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is your code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;

Data Want;
sest have;
Length Period 4.; 
Period = 0;

boundary1 = "&amp;amp;startDate"d;
boundary2 = intnx("month", "&amp;amp;startDate"d, 1, 'e');
boundary3 = intnx("month", "&amp;amp;startDate"d, 4, 'e');
boundary4 = intnx("month", "&amp;amp;startDate"d, 7, 'e');

format boundary: date9.;

if boundary1 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary2 then Period = 1;/*Decreasing 1 month because it cannot excess the StartDate*/
if boundary2 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary3 then Period = 2;/*Decreasing 3 months*/
if boundary3 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary4 then Period = 3;/*Decreasing 3 months*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then someday they want to implement your code for different data set. Let's say they want to use following data set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Format Pro_End_Date_Ym DATE9.;
Infile Datalines Missover;
Input Pro_End_Date_Ym;
Datalines;
10826
10827
10828
10829
10830
10850
10870
10880
10991
10999
11111
11222
11333
11444
11555
11666
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then they realize some of the periods comes zero and they also don't know SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to prevent this situation. Could I make myself clear?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think Macro code is only solution, what do you think?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 22:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278865#M56138</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-20T22:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278868#M56140</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EndDate also will change like this -&amp;gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=31DEC1991;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jun 2016 22:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278868#M56140</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-20T22:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278879#M56144</link>
      <description>&lt;P&gt;No. Given what you've shown I still believe any logic you implement via macros can easily be accomodated in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rules need to be clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if the period is 0? What defines a period, is it the 3 months periods from Dec to Feb, Mar - May, Jun-Aug, Sep - Dec, except truncated for if the start date is somewhere in between? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make it a macro to take a different data set, different variable and start period. That's fine. But the logic to calculate the periods should&amp;nbsp;be implemented as a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_intervals(datain = , variable = , date_start= , date_end =, dataout=);


data &amp;amp;dataout;
set &amp;amp;datain;

*date logic stuff goes here;


run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 00:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278879#M56144</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-21T00:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278893#M56151</link>
      <description>&lt;P&gt;So if you want to divide the internal into 3 month "PERIODS" you can do it arithmetically. No need for loops of any kind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date @@ ;
  informat date date9. ;
  format date date9. ;
datalines;
22AUG1989 23AUG1989 24AUG1989 25AUG1989 26AUG1989 15SEP1989
05OCT1989 15OCT1989 03FEB1990 11FEB1990 03JUN1990 22SEP1990
11JAN1991 02MAY1991 21AUG1991 10DEC1991
;;;;

%let startdate=31jul1989;

data want;
  set have;
  period = 1 + ceil((intck('month',"&amp;amp;startdate"d,date)-1)/3) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It might even be possible for you to create the STARTDATE macro variable from the input data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
  select intnx('month',min(date),-1,'e') format=date9.
    into :startdate
  from have
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jun 2016 02:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/278893#M56151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-21T02:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280236#M56587</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m so sorry I tried something but I could not handle it. Actually, I understood @Tom’s latest method and it worked in my sample data set fine but it didn’t work in my real data set. The results didn’t match the manaul method’s results &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Do you have an idea why the results cannot match with each other?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also try to create macro structure but I couldn’t handle it &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; I’m so sorry. My following sample does not seem fine, I know, I’ll re-examine it but could you help me, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the other hand,&amp;nbsp;first row should be like that -&amp;gt; if '31JUL1989'd &lt;STRONG&gt;&amp;lt;=(Less Than or Equal To) &lt;/STRONG&gt;PRO_END_DATE_YM &amp;lt;= '31AUG1989'd then Period = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much both of you again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
Set Have;
Length Period 4.; 
Period = 0;
if '31JUL1989'd &amp;lt;= PRO_END_DATE_YM &amp;lt;= '31AUG1989'd then Period = 1;
/*Decreasing 1 monthbecause it cannot excess the StartDate*/
/*This part changed being Less Than or Equal To instead of Less Than*/
.......;
Run;

Data Have;
Format Pro_End_Date_Ym DATE9.;
Infile Datalines Missover;
Input Pro_End_Date_Ym;
Datalines;
10826
10827
10828
10829
10830
10850
10870
10880
10991
10999
11111
11222
11333
11444
11555
11666
;
Run;

%Let Start_Date=31JUL1989;
%Let End_Date=31DEC1991;
%Macro Date_Intervals(A,B,C,DataIn,DataOut,Date_Start,Date_End);
Data DataOut.;
Set DataIn.;
Length Period 4.; 
Period = 0;

%If &amp;amp;A.=1  %Then %Do;
Boundary&amp;amp;A. = "&amp;amp;Date_Start"d;
%End;
Boundary&amp;amp;A.=Intnx("Month", "&amp;amp;Date_Start"d, &amp;amp;B., "E");

Format Boundary: Date9.;

If Boundary&amp;amp;A. &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary&amp;amp;C. then Period = &amp;amp;i.;

Run;

%Mend Date_Intervals;
%Macro Dynamic;

%Let i=1;
%Let j=1;
%Let x=2;
%Do %Until(&amp;amp;End_Date.);
%Date_Intervals(&amp;amp;i.,&amp;amp;j.,&amp;amp;x.,Have,Want,&amp;amp;Start_Date.,&amp;amp;End_Date.);
%Let i=&amp;amp;i.+1;
%Let j=&amp;amp;j.+3;
%Let x=&amp;amp;x.+1;
%End;
%Mend;

%Dynamic;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Jun 2016 17:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280236#M56587</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-26T17:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280240#M56590</link>
      <description>&lt;P&gt;Stop. What are the rules for calculating the variable period in words?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't define the problem you won't be able to solve it. And we can't help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2016 17:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280240#M56590</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-26T17:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280280#M56606</link>
      <description>&lt;P&gt;Hello again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me try to tell you, I think I cannot get your explanations &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Sorry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We define the date values. First one is Start Date and second one is End Date. We need to&amp;nbsp;use as a&amp;nbsp;base for End Date. It should decrease three(month) by three. But if End Date will excess Start Date then it should be over on Start Date and symbol should like -&amp;gt; "&amp;lt;=".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, your following code is correct but the point is that I should make suitable this code for every input data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are 10 Boundary in your following code so there will be 10 periods&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in you boundary2, boundary3 and boundary4 statements 1,4 and 7 values should be parametric.&lt;/P&gt;&lt;P&gt;Periods also should be parametric and boundaries too. I try yo build this structure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I could make myself clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let StartDate=31JUL1989;
%Let EndDate=28FEB1990;

Data Want;
sest have;
Length Period 4.; 
Period = 0;

boundary1 = "&amp;amp;startDate"d;
boundary2 = intnx("month", "&amp;amp;startDate"d, 1, 'e');
boundary3 = intnx("month", "&amp;amp;startDate"d, 4, 'e');
boundary4 = intnx("month", "&amp;amp;startDate"d, 7, 'e');

format boundary: date9.;

if boundary1 &amp;lt;= PRO_END_DATE_YM &amp;lt;= boundary2 then Period = 1;/*Decreasing 1 month because it cannot excess the StartDate*/
if boundary2 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary3 then Period = 2;/*Decreasing 3 months*/
if boundary3 &amp;lt; PRO_END_DATE_YM &amp;lt;= boundary4 then Period = 3;/*Decreasing 3 months*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2016 20:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280280#M56606</guid>
      <dc:creator>ertr</dc:creator>
      <dc:date>2016-06-26T20:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280282#M56608</link>
      <description>&lt;P&gt;Still not clear why the first interval is 1 not 3, it's not past the end date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2016 20:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280282#M56608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-26T20:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Loop -  To Create An Automatic Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280284#M56610</link>
      <description>&lt;P&gt;Work backwards if your definition is from end to start date. Don't try and pre calculate the dates either.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Use intck to determine number of boundaries&lt;/P&gt;
&lt;P&gt;2. Create a do loop with that boundary&lt;/P&gt;
&lt;P&gt;3. Increment a date variable using the I to increment. It doesn't matter if you go past start date, but you can use MIN(start_date, boundary) to ensure that you don't.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Assign periods&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if the data has dates outside start/end date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can code that logic, I'll try and post code later if someone else already hasn't. The only macro variables in the code should be the start and end date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is this going to be used? Will there be multiple start/end dates for a single data set?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usage ultimately determines end design.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what we needed to see to help answer your question except I think your last sentence is supposed to be if the last boundary is past the start date not end date past the start.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;We define the date values. First one is Start Date and second one is End Date. We need to&amp;nbsp;use as a&amp;nbsp;base for End Date. It should decrease three(month) by three. But if End Date will excess Start Date then it should be over on Start Date and symbol should like -&amp;gt; "&amp;lt;=".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2016 21:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Loop-To-Create-An-Automatic-Loop/m-p/280284#M56610</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-26T21:10:54Z</dc:date>
    </item>
  </channel>
</rss>

