<?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 Do loop - Skip a section when value fail a test in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345981#M79686</link>
    <description>It is so great.&lt;BR /&gt;Thank you so much for your help.&lt;BR /&gt;HHC</description>
    <pubDate>Thu, 30 Mar 2017 22:02:55 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2017-03-30T22:02:55Z</dc:date>
    <item>
      <title>Macro Do loop - Skip a section when value fail a test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345253#M79401</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My Macro has 2 sections. At the end of section 1, I get a mean value for variable, say xyz. If this mean is less than 10, I want SAS skip section 2 to move on a new loop.&lt;/P&gt;
&lt;P&gt;Can you please help me with that?&lt;/P&gt;
&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro comp;
%local i j;
%do i=1 %to 100;
  %do j=1 %to 100;
		
	*PART 1: A lot of code	;

			proc means data=abc;
			var xyz;
			output out=check_value
			mean=mean_xyz;
			run;
	
	
			IF mean_xyz&amp;lt;10 THEN SKIP THE PART2 Code below

	*PART 2: A lot of code	;
		

%end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Mar 2017 04:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345253#M79401</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-03-29T04:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do loop - Skip a section when value fail a test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345254#M79402</link>
      <description>&lt;P&gt;You probably need the&amp;nbsp;conditional logic from %if.&lt;/P&gt;
&lt;P&gt;To be able to do so, you need the mean_xyz as a macro variable,&amp;nbsp;something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set check_value;
   call symputx('MEAN_XYZ',mean_xyz);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 04:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345254#M79402</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-29T04:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do loop - Skip a section when value fail a test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345261#M79407</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;I have added the DATA step suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt; and a macro %IF.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro comp;
%local i j;
%do i=1 %to 100;
  %do j=1 %to 100;
		
	*PART 1: A lot of code	;
	proc means data=abc;
			var xyz;
			output out=check_value
			mean=mean_xyz;
			run;
	data _null_;
      set check_value;
      call symputx('MEAN_XYZ',mean_xyz);
      run;
	
	%IF %sysevalf(&amp;amp;mean_xyz&amp;gt;=10) %THEN %do;

	*PART 2: A lot of code	;
	%end;	

%end;
%end;
%mend comp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice that in the %IF the %SYSEVALF is used.&amp;nbsp; This is important because the mean (&amp;amp;MEAN_XYZ) will probably not be an integer.&amp;nbsp; Non-integers would cause an alphabetic comparison (10&amp;lt;9. = true).&amp;nbsp; I also reversed the comparison logic so that i could use a %DO block.&amp;nbsp; There is also a %GOTO (much like the DATA step GOTO), but i am not a fan of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 05:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345261#M79407</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2017-03-29T05:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Do loop - Skip a section when value fail a test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345981#M79686</link>
      <description>It is so great.&lt;BR /&gt;Thank you so much for your help.&lt;BR /&gt;HHC</description>
      <pubDate>Thu, 30 Mar 2017 22:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Do-loop-Skip-a-section-when-value-fail-a-test/m-p/345981#M79686</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-03-30T22:02:55Z</dc:date>
    </item>
  </channel>
</rss>

