<?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: SAS help - Batch Mode - Running macros in loop with %abort statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668926#M200577</link>
    <description>&lt;P&gt;Thanks for your proposal. Based on the documentation, for batch jobs with %Abort cancel option would SAS program and SAS system.&amp;nbsp;&lt;/P&gt;&lt;P&gt;CANCEL &amp;lt;FILE&amp;gt;&lt;/P&gt;&lt;DIV class="xisDoc-argumentDescription"&gt;&lt;P class="xisDoc-paraSimpleFirst"&gt;causes the cancellation of the current submitted statements. The results depend on the method of operation.&lt;/P&gt;&lt;P class="xisDoc-paraSimple"&gt;If the method of operation is batch mode and noninteractive mode, use the CANCEL option to do the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;The entire SAS program and SAS system are terminated.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;The error message is written to the SAS log&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested the approach you have mentioned above and faced two issues.&lt;/P&gt;&lt;P&gt;1. The value of iteration variable is always 3 (max. loop number) for all the iterations of the program.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. If the program encounters %abort cancel in the middle of iterations, for example 2nd iteration, it didn't execute the 3rd iteration of the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if I'm missing something. Thanks again!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 13 Jul 2020 19:01:15 GMT</pubDate>
    <dc:creator>Ramesh_165</dc:creator>
    <dc:date>2020-07-13T19:01:15Z</dc:date>
    <item>
      <title>SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668419#M200360</link>
      <description>&lt;P&gt;Hi There,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m looking for a solution to use %abort statement in one of the many sub-macros in a batch environment with the below need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I’m running a macro (lets say, &lt;STRONG&gt;Main_Macro&lt;/STRONG&gt;) with quite a few submacros. One of the sub-macro is &lt;STRONG&gt;quit_on_error&lt;/STRONG&gt; which has an &lt;STRONG&gt;%abort&lt;/STRONG&gt; (without argument) statement. The &lt;STRONG&gt;quit_on_error&lt;/STRONG&gt; macro is called from multiple places of the sub-macros to quit the process if there is any error in any of the macros.&lt;/LI&gt;&lt;LI&gt;I want to run the Main_Macro in loop, lets say, for each US State. When a particular run (particular state) of the &lt;STRONG&gt;Main_Macro&lt;/STRONG&gt; fails (%abort ed by &lt;STRONG&gt;quit_on_error&lt;/STRONG&gt;), I want other states to continue. I achieved this using CALL EXECUTE statement to call the Main_Macro.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the problem is I tested the above two points in “&lt;STRONG&gt;interactive”&lt;/STRONG&gt; mode, and it was working fine. Even though a particular run of the &lt;STRONG&gt;Main_Macro&lt;/STRONG&gt; failed, the other runs were attempted to process.&lt;/P&gt;&lt;P&gt;But when I put this code in “&lt;STRONG&gt;batch”&lt;/STRONG&gt; mode, when a particular run of the &lt;STRONG&gt;Main_Macro&lt;/STRONG&gt; failed all the subsequent process are suspended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe this is due to the behavior of &lt;STRONG&gt;%abort&lt;/STRONG&gt; statement between interactive and batch modes.&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0f7j2zr6z71nqn1fpefnmulzazf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0f7j2zr6z71nqn1fpefnmulzazf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to have the rest of the runs to continue process even though the previous run failed in batch mode? Any help or insights are much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Ramesh&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 17:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668419#M200360</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-07-10T17:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668446#M200374</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213043" target="_blank"&gt;Ramesh_165&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;Instead of %abort statement try using &lt;A href="https://go.documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0qyygqt5a69xnn1rhfju3kjs8al.htm&amp;amp;docsetVersion=3.1&amp;amp;locale=en" rel="nofollow"&gt;%return statement&lt;/A&gt; which causes &lt;EM&gt;&lt;STRONG&gt;normal&lt;/STRONG&gt;&lt;/EM&gt; termination of the currently executing macro.&lt;/P&gt;
&lt;P&gt;I also posted my reply in the &lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_self"&gt;CALL EXECUTE made easy for SAS data-driven programming&lt;/A&gt; blog post.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 19:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668446#M200374</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-07-10T19:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668480#M200386</link>
      <description>&lt;P&gt;Hello Leonid,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I'm using %abort instead of %return statement is because I don't want the subsequent macro calls within the Main_Macro to execute once the QuitOnError macro is called.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see the below example where the Main_Macro has n-number of macros, and once the QuitOnError macro is executed from any of the macros, no subsequent statements or macros should execute. In this case I have coded, both %return and %abort statement conditionally to show the execution difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPTIONS NOMPRINT NOMLOGIC NOSYMBOLGEN NONOTES;&lt;/P&gt;&lt;P&gt;%Macro QuitOnError(abortOrReturn);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;abortOrReturn. in QuitOnError macro;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;abortOrReturn = abort %then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %abort;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %if &amp;amp;abortOrReturn = return %then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %return;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;%Macro macro_n(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Macron successful;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM SASHELP.CLASS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Class Table count = &amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;%Macro Macro_4(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Macro4 successful;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM SASHELP.CLASS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Class Table count = &amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;%Macro Macro_3(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. -&amp;nbsp; Macro3 Errored;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - calling QuitOnError from Macro3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;iteration = 2 %then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %QuitOnError(abort);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %QuitOnError(return);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM SASHELP.CLASS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Class Table count = &amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;%Macro Macro_2(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Macro2 started;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM SASHELP.CLASS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Class Table count = &amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;%Macro Macro_1(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Macro1 successful;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM SASHELP.CLASS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;iteration. - Class Table count = &amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro Main_Macro(iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Macro_1(&amp;amp;iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Macro_2(&amp;amp;iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Macro_3(&amp;amp;iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Macro_4(&amp;amp;iteration);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Macro_n(&amp;amp;iteration);&lt;/P&gt;&lt;P&gt;%Mend;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO i = 1 TO 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL EXECUTE('%NRSTR(%Main_Macro('||STRIP(i)||'))');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Put statement Log outputs of the above code:&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(1)&lt;/P&gt;&lt;P&gt;1 - Macro1 successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macro2 started&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;1 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;return in QuitOnError macro&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macro4 successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macron successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(2)&lt;/P&gt;&lt;P&gt;2 - Macro1 successful&lt;/P&gt;&lt;P&gt;2 - Class Table count = 19&lt;/P&gt;&lt;P&gt;2 - Macro2 started&lt;/P&gt;&lt;P&gt;2 - Class Table count = 19&lt;/P&gt;&lt;P&gt;2 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;2 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;abort in QuitOnError macro&lt;/P&gt;&lt;P&gt;ERROR: Execution terminated by an %ABORT statement.&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(3)&lt;/P&gt;&lt;P&gt;3 - Macro1 successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 19&lt;/P&gt;&lt;P&gt;3 - Macro2 started&lt;/P&gt;&lt;P&gt;3 - Class Table count = 19&lt;/P&gt;&lt;P&gt;3 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;3 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;return in QuitOnError macro&lt;/P&gt;&lt;P&gt;3 - Class Table count = 19&lt;/P&gt;&lt;P&gt;3 - Macro4 successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 19&lt;/P&gt;&lt;P&gt;3 - Macron successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 19&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;Based on the log, I'm expecting the 2nd iteration behavior in my process, so I'm using %abort statement and not %return statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though the 2nd iteration is aborted, it is running the 3rd iteration in interactive mode.&lt;/P&gt;&lt;P&gt;But in the batch mode, the process works fine until 2nd iteration. 3rd iteration starts fine, but all the observations are 0. I think it is because the OBS option is set 0 when %abort statement is executed in batch mode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is log of the same code from batch mode:&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(1)&lt;/P&gt;&lt;P&gt;1 - Macro1 successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macro2 started&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;1 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;return in QuitOnError macro&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macro4 successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;1 - Macron successful&lt;/P&gt;&lt;P&gt;1 - Class Table count = 19&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(2)&lt;/P&gt;&lt;P&gt;2 - Macro1 successful&lt;/P&gt;&lt;P&gt;2 - Class Table count = 19&lt;/P&gt;&lt;P&gt;2 - Macro2 started&lt;/P&gt;&lt;P&gt;2 - Class Table count = 19&lt;/P&gt;&lt;P&gt;2 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;2 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;abort in QuitOnError macro&lt;/P&gt;&lt;P&gt;ERROR: Execution terminated by an %ABORT statement.&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + %Main_Macro(3)&lt;/P&gt;&lt;P&gt;3 - Macro1 successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 0&lt;/P&gt;&lt;P&gt;3 - Macro2 started&lt;/P&gt;&lt;P&gt;3 - Class Table count = 0&lt;/P&gt;&lt;P&gt;3 -&amp;nbsp; Macro3 Errored&lt;/P&gt;&lt;P&gt;3 - calling QuitOnError from Macro3&lt;/P&gt;&lt;P&gt;return in QuitOnError macro&lt;/P&gt;&lt;P&gt;3 - Class Table count = 0&lt;/P&gt;&lt;P&gt;3 - Macro4 successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 0&lt;/P&gt;&lt;P&gt;3 - Macron successful&lt;/P&gt;&lt;P&gt;3 - Class Table count = 0&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that the Main_Macro was written some back this way to use %abort statement. Now I’m just trying to run it in loop without not making much changes to code. There might be some elegant ways to check for errors at the start of each macro and go to the end if there were any errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I’m trying to see if there is a possibility at all to achieve the need without making the big change as there close to couple hundred macros within the Main_Macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for reading this detailed note, and taking sometime to think about solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ramesh&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 20:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668480#M200386</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-07-10T20:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668496#M200398</link>
      <description>&lt;P&gt;Right. Don't do that.&lt;/P&gt;
&lt;P&gt;If you want to run a series of jobs then run them as a series of jobs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas program1
sas program2
sas program3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jul 2020 22:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668496#M200398</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-10T22:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668497#M200399</link>
      <description>&lt;P&gt;Have you checked out the SAS option ERRORABEND? If this option is set then your batch program will abort when there is an error anywhere in your SAS job. There is no need to add checking steps all over your code in that case. I'm a fan of keeping coding practices simple and find the SAS options SYNTAXCHECK and&amp;nbsp;ERRORABEND add all the control I need.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 22:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668497#M200399</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-07-10T22:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668749#M200517</link>
      <description>&lt;P&gt;What I normally do when wanting to break out of a program, but not end the SAS session, is to use the %ABORT CANCEL FILE statement; that only terminates the %INCLUDE file it is called from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you could make a SAS program instead of your main macro, e.g. Main.SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     %Macro_1(&amp;amp;iteration);
     %Macro_2(&amp;amp;iteration);
     %Macro_3(&amp;amp;iteration);
     %Macro_4(&amp;amp;iteration);
     %Macro_n(&amp;amp;iteration);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In your QUIT_ON_ERROR macro, you use %ABORT CANCEL FILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your datastep could then be rewritten as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
     DO i = 1 TO 3;
           CALL EXECUTE(cats('%NRSTR(%let Iteration=',i,';%include Main.SAS;)'));
     END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2020 07:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668749#M200517</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-07-13T07:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668912#M200570</link>
      <description>&lt;P&gt;Thanks for your response.&lt;/P&gt;&lt;P&gt;ERRORABEND option is set to NOERRORABEND. But as per the documentation, but the options would set OBS=0 when there is an error. So in my case, changing that may not help as&amp;nbsp; I want the next iteration of the Main_Macro to run normally by just aborting the errored iteration.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668912#M200570</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-07-13T18:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668919#M200573</link>
      <description>&lt;P&gt;The number of jobs is going to be varying. Thats why I'm controlling and calling Main_Macro within a datastep. As of now I have to run around 400+ iterations (this could go up to 2000+) of Main_Macro, and I have split them into 10 jobs. Still each job has to run 40+ iterations of Main_Macro. The problem is, in any of those jobs, if any iteration of the Main_Macro fails, the rest of the iterations of Main_Macro don't work. I believe SAS goes into a state where it won't process anything after that. I tried printing the options from dictionary.options table after the error, but no options are printed on the log. So either, SAS options are completely removed, or SAS is in a state where it can't process any datasets.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668919#M200573</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-07-13T18:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668923#M200575</link>
      <description>&lt;P&gt;I recommend running each separate job in its own session.&amp;nbsp; Do you have SAS/Connect licensed?&amp;nbsp; If so then it is pretty easy.&lt;/P&gt;
&lt;P&gt;For example here is step I used to call a macro named EXTRACT_SUB in a separate SAS session.&amp;nbsp; If it crashes it does not impact the current session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*----------------------------------------------------------------------------;
* Create remote session and submit extract call ;
*----------------------------------------------------------------------------;
signon X sascmd="!sascmd -altlog '&amp;amp;outdir/&amp;amp;study/extract.log'";
%syslput study=&amp;amp;study /remote=X;
%syslput outdir=&amp;amp;outdir /remote=X;
rsubmit x;
  libname out "&amp;amp;outdir/&amp;amp;study";
  options insert=(sasautos="%gdir(macros)") compress=yes errorabend;
  %extract_sub(&amp;amp;study,&amp;amp;outdir);
  libname _all_ clear;
endrsubmit;
signoff x;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jul 2020 18:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668923#M200575</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-13T18:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668926#M200577</link>
      <description>&lt;P&gt;Thanks for your proposal. Based on the documentation, for batch jobs with %Abort cancel option would SAS program and SAS system.&amp;nbsp;&lt;/P&gt;&lt;P&gt;CANCEL &amp;lt;FILE&amp;gt;&lt;/P&gt;&lt;DIV class="xisDoc-argumentDescription"&gt;&lt;P class="xisDoc-paraSimpleFirst"&gt;causes the cancellation of the current submitted statements. The results depend on the method of operation.&lt;/P&gt;&lt;P class="xisDoc-paraSimple"&gt;If the method of operation is batch mode and noninteractive mode, use the CANCEL option to do the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;The entire SAS program and SAS system are terminated.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;The error message is written to the SAS log&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested the approach you have mentioned above and faced two issues.&lt;/P&gt;&lt;P&gt;1. The value of iteration variable is always 3 (max. loop number) for all the iterations of the program.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. If the program encounters %abort cancel in the middle of iterations, for example 2nd iteration, it didn't execute the 3rd iteration of the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if I'm missing something. Thanks again!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 13 Jul 2020 19:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/668926#M200577</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-07-13T19:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS help - Batch Mode - Running macros in loop with %abort statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/693038#M211255</link>
      <description>&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;One of the difference between batch and interactive mode is what happens when SAS encounters an error. &amp;nbsp;&amp;nbsp;When an error occurs in interactive SAS, only the step that produces the error stops processing. &amp;nbsp;In batch, an error causes SAS to go into syntax-check mode. &amp;nbsp;This means that the system option OBS= is set to 0 and all subsequent steps are compiled only and not executed. &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;Setting &lt;SPAN class="cse36438741"&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=lesysoptsref&amp;amp;docsetTarget=n014qbvh3po8w5n1qlqbzr22vtg0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;the NOSYNTAXCHECK system option &lt;/A&gt;&amp;nbsp;will&amp;nbsp;&lt;/SPAN&gt;have batch mode act like interactive mode.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;options nosyntaxcheck;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;Adding this NOSYNTAXCHECK option solved the above mentioned problem.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="cs25c823211"&gt;&lt;SPAN style="font-size: 16.0pt;"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216503"&gt;@all&lt;/a&gt;. - Thank you so much for your time.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 22:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-help-Batch-Mode-Running-macros-in-loop-with-abort-statement/m-p/693038#M211255</guid>
      <dc:creator>Ramesh_165</dc:creator>
      <dc:date>2020-10-20T22:55:29Z</dc:date>
    </item>
  </channel>
</rss>

