<?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: Using a &amp;quot;if&amp;quot; statement after a do loop to filter out information in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275715#M55170</link>
    <description>&lt;P&gt;And anothe approach with DO Until:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list;
   snapshot = input("&amp;amp;strte.",yymmn6.);
   do until (snapshot &amp;gt; input("&amp;amp;ende",yymmn6.));
      output;
      snapshot= intnx('month',snapshot,1);
   end;
   format snapshot yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Exercise for the interested reader to modify to&amp;nbsp; a DO WHILE loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2016 15:44:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-06-07T15:44:06Z</dc:date>
    <item>
      <title>Using a "if" statement after a do loop to filter out information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275548#M55103</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following SAS code creates a dataset list that contains the variable snapshot (in yyyymm format) from 200309 to 201603. There is a "if" condition that is supposed to result in only the snapshots 200309 to 201506 being populated. However, the "if" condition does not work. Please advise on why this is so. Any help would be much appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let   strte=200309;
%let   ende=201506;

%macro download;

data list(drop=i);
	do i=0 to 150;
		index=i;
		snapshot=put(intnx('month',input("&amp;amp;strte.",yymmn6.),i),yymmn6.);
		output;
	end;
	if snapshot&amp;lt;="&amp;amp;ende.";
run;


%mend download;


%download;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 02:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275548#M55103</guid>
      <dc:creator>johntan_123</dc:creator>
      <dc:date>2016-06-07T02:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using a "if" statement after a do loop to filter out information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275553#M55104</link>
      <description>&lt;P&gt;You must make the OUTPUT statement conditional&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let   strte=200309;
%let   ende=201506;

%macro download;

data list(drop=i);
	do i=0 to 150;
		index=i;
		snapshot=put(intnx('month',input("&amp;amp;strte.",yymmn6.),i),yymmn6.);
		if snapshot&amp;lt;="&amp;amp;ende." then output;
	        end;
run;


%mend download;


%download;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OUTPUT is an executable statement. You can't cancel its effect with later statements.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 02:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275553#M55104</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-07T02:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using a "if" statement after a do loop to filter out information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275595#M55120</link>
      <description>&lt;P&gt;Why is this in a macro, there is no need for it. &amp;nbsp;You can also write your code so that the do loop executes only for the number of intervals between the two items (note, if you avoided putting data in macro variables your life would also be much easier). &amp;nbsp;So your code can actually be written as:&lt;/P&gt;
&lt;PRE&gt;%let   strte=200309;
%let   ende=201506;
data list(drop=i);
  do i=0 to intck('month',input("&amp;amp;strte.",yymmn6.),input("&amp;amp;ende",yymmn6.));
    index=i;
    snapshot=put(intnx('month',input("&amp;amp;strte.",yymmn6.),i),yymmn6.);
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;This will then only loop for the needed number of iterations and outputs each time, whereas the do with and if statement will run 150 times regardless of how many times it needs to.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 08:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275595#M55120</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-07T08:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using a "if" statement after a do loop to filter out information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275715#M55170</link>
      <description>&lt;P&gt;And anothe approach with DO Until:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list;
   snapshot = input("&amp;amp;strte.",yymmn6.);
   do until (snapshot &amp;gt; input("&amp;amp;ende",yymmn6.));
      output;
      snapshot= intnx('month',snapshot,1);
   end;
   format snapshot yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Exercise for the interested reader to modify to&amp;nbsp; a DO WHILE loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 15:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-quot-if-quot-statement-after-a-do-loop-to-filter-out/m-p/275715#M55170</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-07T15:44:06Z</dc:date>
    </item>
  </channel>
</rss>

