<?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: How to exit macro without ending SAS session?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994321#M380516</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro loop_a(x, xtest);
	%do i=1 %to 50;
		%put "i=&amp;amp;i. x=&amp;amp;x. xtest=&amp;amp;xtest.";
		%if &amp;amp;x.&amp;gt; %sysfunc(floor(&amp;amp;xtest.)) %then %return;
	%end;
%mend;

%macro loop_b();
	%do i=1 %to 10;
		%let y=%sysfunc(ranuni(&amp;amp;i.))*100;
		%put "y=&amp;amp;y.";
		%loop_a(&amp;amp;i., &amp;amp;y.);
	%end;
%mend;

%loop_b();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When run, how many loops loop_b() do?!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2026 10:48:44 GMT</pubDate>
    <dc:creator>hellohere</dc:creator>
    <dc:date>2026-09-29T10:48:44Z</dc:date>
    <item>
      <title>How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994177#M380510</link>
      <description>Need to exit one macro but without ending sas session[other macros]?!

%return seems end the session, so does %abort.</description>
      <pubDate>Sun, 27 Sep 2026 15:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994177#M380510</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2026-09-27T15:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994197#M380511</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0qyygqt5a69xnn1rhfju3kjs8al.htm" target="_blank" rel="noopener"&gt;%RETURN&lt;/A&gt; terminates the current macro, not your SAS session. You need to post your code so we can figure out what is happening.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Sep 2026 19:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994197#M380511</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2026-09-27T19:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994216#M380513</link>
      <description>&lt;P&gt;The %RETURN Macro Statement indeed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also use the %GOTO Macro Statement (&lt;SPAN class="xisDoc-keyword"&gt;%GOTO&lt;/SPAN&gt; &lt;EM class="xisDoc-userSuppliedValue"&gt;label&lt;/EM&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;) a lot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example: Providing Exits in a Large Macro&lt;/STRONG&gt;&lt;BR /&gt;(&lt;SPAN&gt;The %GOTO statement is useful in large macros when you want to provide an exit if an error occurs.)&lt;/SPAN&gt;&lt;BR /&gt;This example can be found on this SAS doc page:&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_078/mcrolref/p0jfeh75p72icen1ddd9una5zbmm.htm" target="_blank" rel="noopener"&gt;%GOTO Macro Statement: SAS Help Center&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ciao,&lt;BR /&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2026 07:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994216#M380513</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2026-09-28T07:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994321#M380516</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro loop_a(x, xtest);
	%do i=1 %to 50;
		%put "i=&amp;amp;i. x=&amp;amp;x. xtest=&amp;amp;xtest.";
		%if &amp;amp;x.&amp;gt; %sysfunc(floor(&amp;amp;xtest.)) %then %return;
	%end;
%mend;

%macro loop_b();
	%do i=1 %to 10;
		%let y=%sysfunc(ranuni(&amp;amp;i.))*100;
		%put "y=&amp;amp;y.";
		%loop_a(&amp;amp;i., &amp;amp;y.);
	%end;
%mend;

%loop_b();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When run, how many loops loop_b() do?!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2026 10:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994321#M380516</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2026-09-29T10:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994329#M380518</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro loop_a(x, xtest);
	%do i=1 %to 50;
		%put "i=&amp;amp;i. x=&amp;amp;x. xtest=&amp;amp;xtest.";
		%if &amp;amp;x.&amp;gt; %sysfunc(floor(&amp;amp;xtest.)) %then %return;
	%end;
%mend;

%macro loop_b();
	%do i=1 %to 10;
		%let y=%sysfunc(ranuni(&amp;amp;i.))*100;
		%put "y=&amp;amp;y.";
		%loop_a(&amp;amp;i., &amp;amp;y.);
	%end;
%mend;

%loop_b();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When run, how many loops loop_b() do?!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This would be better as a new question.&amp;nbsp; loop_b will only iterate once, because in the definition of loop_a (and loop_b), you forgot to create the macro variable &amp;amp;i as a &lt;EM&gt;local&lt;/EM&gt; macro variable.&amp;nbsp; Therefore when %loop_a executes, instead of creating its own macro variable &amp;amp;i, it will use the existing macro variable &amp;amp;i that is owned by %loop_b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the first iteration of %loop_b, %loop_a is called one time and iterates 50 times, and after that &amp;amp;i will have the value 51.&amp;nbsp; %loop_b will not iterate a second time, because 51 is greater than 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop_a();
  %* local i ;
  %do i=1 %to 50;
    %put &amp;amp;=sysmacroname &amp;amp;=i ;
    %put _user_ ;
  %end;
%mend;

%macro loop_b();
  %* local i ;
  %do i=1 %to 10;
    %put &amp;amp;=sysmacroname &amp;amp;=i ;
    %loop_a()
  %end;
%mend;

%loop_b()&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2026 12:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994329#M380518</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-09-29T12:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994330#M380519</link>
      <description>&lt;P&gt;thanks for the point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if not explicitly decleared as local, the i/j variable at different macro will interfere?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2026 13:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994330#M380519</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2026-09-29T13:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to exit macro without ending SAS session?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994331#M380520</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks for the point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if not explicitly decleared as local, the i/j variable at different macro will interfere?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, exactly, this is a macro variable "collision". Luckily your collision resulted in a loop that ends prematurely.&amp;nbsp; If you had done it the other way around, it would have created an infinite loop.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should "always" declare macro variables you create inside a macro to be local.&amp;nbsp; Unless you have a very good reason not to do so (which is rare).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2026 13:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exit-macro-without-ending-SAS-session/m-p/994331#M380520</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-09-29T13:13:09Z</dc:date>
    </item>
  </channel>
</rss>

