<?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 conditionally abort all code without closing SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-conditionally-abort-all-code-without-closing-SAS/m-p/614523#M179660</link>
    <description>&lt;P&gt;I presume you are running SAS interactively, since you want SAS to stop processing code, but not close.&amp;nbsp; That wouldn't make sense in a batch environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&amp;nbsp; &lt;STRONG&gt;&amp;nbsp; %abort cancel;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is documented as&lt;/P&gt;
&lt;DIV class="xis-eDocBody"&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-syntax"&gt;
&lt;DIV class="xis-syntaxDescription"&gt;
&lt;DIV class="xis-requiredArgGroup"&gt;
&lt;DIV id="n1tb7562jsd21an1nyxqa433ujh2" class="xis-argDescriptionPair"&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;DIV id="n0uu9z6evawje2n1pqwku72wddo5" class="xis-paraSimple"&gt;If the method of operation is windowing environment and interactive line mode, use the CANCEL option to do the following:&lt;/DIV&gt;
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV id="n03ap1froujp2wn18qebc7hhlg23" class="xis-item"&gt;
&lt;DIV id="p00x9yqhn7rh5vn1qfshitua7xbh" class="xis-paraSimpleFirst"&gt;It only clears the current submitted program.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n0md40hwh896k9n142m20lit4hij" class="xis-item"&gt;
&lt;DIV id="n0s3zrwxu6rlhbn1bmm23gex28fq" class="xis-paraSimpleFirst"&gt;Other subsequent submitted programs are not affected.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n18vojxb6w2jxxn1eczfn3pv0l5o" class="xis-item"&gt;
&lt;DIV id="p18blu2b7td6osn1ple77dhdb2a4" class="xis-paraSimpleFirst"&gt;The error message is written to the SAS log&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in my windows sas session I submitted this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
  proc sql;
    create table t as 
    select * from sashelp.class where sex='X';
  quit;
  %if &amp;amp;sqlobs=0 %then %abort cancel;
  data t2;
    set t;
  run;
%mend test;

%test;
data t3; set t; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because sashelp.class has no obs with sex='X' it made data set T with 0 observations, making &amp;amp;SQLOBS=0 and therefore executing the &lt;STRONG&gt;%abort cancel&lt;/STRONG&gt; statement.&amp;nbsp; The results were&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Did not create data set T2&lt;/LI&gt;
&lt;LI&gt;Did not create data set T3&lt;/LI&gt;
&lt;LI&gt;The windows SAS session stayed open waiting for me to edit the program.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I got the same results running sas/studio.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Dec 2019 06:06:21 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-12-31T06:06:21Z</dc:date>
    <item>
      <title>how to conditionally abort all code without closing SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-conditionally-abort-all-code-without-closing-SAS/m-p/614423#M179606</link>
      <description>&lt;P&gt;I already have a long SAS code that will extract transform and analyze the data. I want to build in some checks for the data in the middle of the program. Ideally, if the check fails, the rest of the code should stop executing so user can review, edit and restart the program where the code stopped.&lt;/P&gt;&lt;P&gt;I tried to use %abort to stop the program, but it only stops the macro and the rest of the program still executes.&lt;/P&gt;&lt;P&gt;I tried to use %abort abend and %abort return, it stopped executing the rest of the program but also closed SAS (which I do not want).&lt;/P&gt;&lt;P&gt;The documentation for %abort abend and %abort return says: "&lt;SPAN&gt;further action is based on how your operating environment and your site treat jobs that end abnormally".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can anyone help determine a method to either update my "&lt;/SPAN&gt;environment" so SAS is not closed when the "jobs end abnormally" or an alternative method to achieve my desired results. Please do not propose any solutions that requires the rest of the program to be put in a conditional statement as the program combined with multiple instances of this check will make the program unwieldy for future edits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see code I used to test abort feature below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_data;
	j = 1;
	do i = 1 to 10;
		output;
	end;
run;

%macro test_for_duplicates (input_dataset, primary_key);

proc sort data = &amp;amp;input_dataset dupout = duplicate_records nodupkey;
	by &amp;amp;primary_key;
run;

proc sql noprint;
	select count(*) into: dup_obs_count from duplicate_records;
quit;

%if &amp;amp;dup_obs_count. &amp;gt; 0 %then %do;
	
	%put "error message here";
	%abort;

%end;

%mend;

%test_for_duplicates(test_data, j);

%put "rest of program here";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 16:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-conditionally-abort-all-code-without-closing-SAS/m-p/614423#M179606</guid>
      <dc:creator>danxy</dc:creator>
      <dc:date>2019-12-30T16:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to conditionally abort all code without closing SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-conditionally-abort-all-code-without-closing-SAS/m-p/614523#M179660</link>
      <description>&lt;P&gt;I presume you are running SAS interactively, since you want SAS to stop processing code, but not close.&amp;nbsp; That wouldn't make sense in a batch environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&amp;nbsp; &lt;STRONG&gt;&amp;nbsp; %abort cancel;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is documented as&lt;/P&gt;
&lt;DIV class="xis-eDocBody"&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-syntax"&gt;
&lt;DIV class="xis-syntaxDescription"&gt;
&lt;DIV class="xis-requiredArgGroup"&gt;
&lt;DIV id="n1tb7562jsd21an1nyxqa433ujh2" class="xis-argDescriptionPair"&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;DIV id="n0uu9z6evawje2n1pqwku72wddo5" class="xis-paraSimple"&gt;If the method of operation is windowing environment and interactive line mode, use the CANCEL option to do the following:&lt;/DIV&gt;
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV id="n03ap1froujp2wn18qebc7hhlg23" class="xis-item"&gt;
&lt;DIV id="p00x9yqhn7rh5vn1qfshitua7xbh" class="xis-paraSimpleFirst"&gt;It only clears the current submitted program.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n0md40hwh896k9n142m20lit4hij" class="xis-item"&gt;
&lt;DIV id="n0s3zrwxu6rlhbn1bmm23gex28fq" class="xis-paraSimpleFirst"&gt;Other subsequent submitted programs are not affected.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV id="n18vojxb6w2jxxn1eczfn3pv0l5o" class="xis-item"&gt;
&lt;DIV id="p18blu2b7td6osn1ple77dhdb2a4" class="xis-paraSimpleFirst"&gt;The error message is written to the SAS log&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in my windows sas session I submitted this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
  proc sql;
    create table t as 
    select * from sashelp.class where sex='X';
  quit;
  %if &amp;amp;sqlobs=0 %then %abort cancel;
  data t2;
    set t;
  run;
%mend test;

%test;
data t3; set t; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because sashelp.class has no obs with sex='X' it made data set T with 0 observations, making &amp;amp;SQLOBS=0 and therefore executing the &lt;STRONG&gt;%abort cancel&lt;/STRONG&gt; statement.&amp;nbsp; The results were&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Did not create data set T2&lt;/LI&gt;
&lt;LI&gt;Did not create data set T3&lt;/LI&gt;
&lt;LI&gt;The windows SAS session stayed open waiting for me to edit the program.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I got the same results running sas/studio.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2019 06:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-conditionally-abort-all-code-without-closing-SAS/m-p/614523#M179660</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-31T06:06:21Z</dc:date>
    </item>
  </channel>
</rss>

