<?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: Do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463642#M118147</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input start DATE9. vardt DATE9. enddt DATE9.;
FORMAT start Date9. vardt Date9. enddt Date9.;
DATALINES;
1jan2017 11Mar2017 1jan2018
1jan2017 02May2017 1jan2018
1jan2017 11Apr2017 1jan2018
;
run;

Data test2 (Drop = i);
set test1;

ARRAY Months{6};
DO i = 1 to DIM(Months);
	IF vardt &amp;gt;= Start + (30*(i-1)) AND vardt &amp;lt;= Start + (30*i) THEN Months{i}=1;
END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Try this.&lt;/P&gt;</description>
    <pubDate>Sun, 20 May 2018 16:32:02 GMT</pubDate>
    <dc:creator>DanielLangley</dc:creator>
    <dc:date>2018-05-20T16:32:02Z</dc:date>
    <item>
      <title>Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463640#M118145</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to find&amp;nbsp; if a date in a variable falls under Month1,Month2, Month3,Month4....Month6 category using a do loop between startdt and incremented startdate&amp;nbsp; &amp;nbsp;i.e., Startdate+30.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By running the below logic, I get a value for the first record as&amp;nbsp; Month2 and a value for rest of the Months too which is not correct. How can i fix this logic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset--&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;vardt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; enddt&lt;/P&gt;
&lt;P&gt;01Jan2017&amp;nbsp; &amp;nbsp;11Mar2017&amp;nbsp; &amp;nbsp; &amp;nbsp; 01Jan2018&lt;/P&gt;
&lt;P&gt;01Jan2017&amp;nbsp; &amp;nbsp;02May2017&amp;nbsp; &amp;nbsp; &amp;nbsp;01Jan2018&lt;/P&gt;
&lt;P&gt;01Jan2017&amp;nbsp; &amp;nbsp;11Apr2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01Jan2018&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data test2;&lt;BR /&gt;set test1;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;mindt=startdt;&lt;BR /&gt;maxdt=enddt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;array Months(6);&lt;/P&gt;
&lt;P&gt;Mnth=30;&lt;BR /&gt;start=mindt;&lt;/P&gt;
&lt;P&gt;do i = 1 to Months;&lt;/P&gt;
&lt;P&gt;mnth=mnth+30;&lt;/P&gt;
&lt;P&gt;stopdt=maxdt;&lt;BR /&gt; if startdt &amp;lt;= vardt&amp;lt;=startdt+mnth then Months(i)=1;&lt;/P&gt;
&lt;P&gt;end;&lt;BR /&gt;start=start+mnth;&lt;/P&gt;
&lt;P&gt;drop&amp;nbsp; i;&lt;BR /&gt;run;&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;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 May 2018 15:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463640#M118145</guid>
      <dc:creator>new510</dc:creator>
      <dc:date>2018-05-20T15:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463642#M118147</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input start DATE9. vardt DATE9. enddt DATE9.;
FORMAT start Date9. vardt Date9. enddt Date9.;
DATALINES;
1jan2017 11Mar2017 1jan2018
1jan2017 02May2017 1jan2018
1jan2017 11Apr2017 1jan2018
;
run;

Data test2 (Drop = i);
set test1;

ARRAY Months{6};
DO i = 1 to DIM(Months);
	IF vardt &amp;gt;= Start + (30*(i-1)) AND vardt &amp;lt;= Start + (30*i) THEN Months{i}=1;
END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Try this.&lt;/P&gt;</description>
      <pubDate>Sun, 20 May 2018 16:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463642#M118147</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2018-05-20T16:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463644#M118148</link>
      <description>&lt;P&gt;Thank you Daniel.&lt;/P&gt;</description>
      <pubDate>Sun, 20 May 2018 17:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/463644#M118148</guid>
      <dc:creator>new510</dc:creator>
      <dc:date>2018-05-20T17:03:52Z</dc:date>
    </item>
  </channel>
</rss>

