<?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: Conditionally leave %do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808078#M318629</link>
    <description>&lt;P&gt;You should be able to use %GOTO.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro checkit;
%DO i= 1 %to 2;
	data  e ;
		x=2 ;
		if x=&amp;amp;i; 
	run;
%if &amp;amp;i=1 %then %goto finish;
/*    huge code and multiple loops here.....*/
%finish:  %END;
%mend checkit;
 
%checkit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Apr 2022 18:41:56 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-04-15T18:41:56Z</dc:date>
    <item>
      <title>Conditionally leave %do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808074#M318626</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the code as below.&lt;/P&gt;
&lt;P&gt;I want to stop the %do loop at first iteration because dataset e will have 0 obs. So it will not execute more statements inside the loop 1.&amp;nbsp; (because it's a huge code and take very long)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then loop 2 should begin normally and execute till end because dataset&amp;nbsp; e will have observations.&lt;/P&gt;
&lt;P&gt;Any ways to achieve this ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did research and Leave statement can do this in normal do loop but it won't work for macro loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&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;%macro checkit;
%DO i= 1 %to 2;
	data  e ;
		x=2 ;
		if x=&amp;amp;i; 
	run;

/*    huge code and multiple loops here.....*/
%END;
%mend checkit;
 
%checkit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Apr 2022 18:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808074#M318626</guid>
      <dc:creator>chetan3125</dc:creator>
      <dc:date>2022-04-15T18:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally leave %do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808075#M318627</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here :&lt;/P&gt;
&lt;P&gt;SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation | SAS 9.4 / Viya 3.5&lt;BR /&gt;Macro Language Reference&lt;BR /&gt;%GOTO Macro Statement&lt;BR /&gt;Example: Providing Exits in a Large Macro&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0jfeh75p72icen1ddd9una5zbmm.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0jfeh75p72icen1ddd9una5zbmm.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check the n° of observations in your dataset, use this code :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
 if 0 then set sashelp.shoes nobs=count;
 call symput('numobs',trim(left(put(count,11.))));
 STOP;
run;
%PUT &amp;amp;=numobs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 18:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808075#M318627</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-04-15T18:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally leave %do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808078#M318629</link>
      <description>&lt;P&gt;You should be able to use %GOTO.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro checkit;
%DO i= 1 %to 2;
	data  e ;
		x=2 ;
		if x=&amp;amp;i; 
	run;
%if &amp;amp;i=1 %then %goto finish;
/*    huge code and multiple loops here.....*/
%finish:  %END;
%mend checkit;
 
%checkit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Apr 2022 18:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808078#M318629</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-04-15T18:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally leave %do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808142#M318652</link>
      <description>&lt;P&gt;Wrap the code you want to execute conditionally in a %IF &amp;lt;condition&amp;gt; %THEN %DO; %END; block.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2022 07:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-leave-do-loop/m-p/808142#M318652</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-16T07:24:44Z</dc:date>
    </item>
  </channel>
</rss>

