<?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 stop SAS code execution and send email with notification in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911073#M359259</link>
    <description>&lt;P&gt;Use either the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0hp2evpgqvfsfn1u223hh9ubv3g.htm" target="_blank" rel="noopener"&gt;ABORT&lt;/A&gt;&amp;nbsp;data step statement, or the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0f7j2zr6z71nqn1fpefnmulzazf.htm" target="_blank" rel="noopener"&gt;%ABORT&lt;/A&gt;&amp;nbsp;macro statement.&lt;/P&gt;
&lt;P&gt;Use the ABEND option, and specify a non-zero exit code to notify your scheduler about the condition, so it can react properly (schedulers can send notification emails).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the search option here in the communities, or do a Google search for "SAS communities send email from SAS". We have a ton of posts about this.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2024 08:07:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-01-10T08:07:35Z</dc:date>
    <item>
      <title>conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911072#M359258</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to add condition to my code that If some conditions meet then stop run the program and send email with a message.&lt;/P&gt;
&lt;P&gt;Specifically in this example : If number of observations in data set A &amp;lt;5 OR&amp;nbsp;&amp;nbsp;number of observations in data set b&amp;lt;5 then stop run the program and send email "Program Stop running due to low number of obs"&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;Can you show the full code? thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*conditionally stop SAS code execution*/
/*conditionally stop SAS code execution*/
/*conditionally stop SAS code execution*/
Data A;
Input ID Name$ Height;
cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

Data B;
Input ID Name$ Weight;
cards;
2 A 2
4 B 3
7 D 5
;
run;

proc sql noprint;
select count(*) as nr_A into :nr_A
from A
;
quit;
%put &amp;amp;nr_A;
proc sql noprint;
select count(*) as nr_B  into :nr_B
from B
;
quit;
%put &amp;amp;nr_B;


/*Here I want to add condition to code execution*/
/*IF &amp;amp;nr_A&amp;lt;5 OR &amp;amp;nr_B&amp;lt;5 then STOP execustion and send email "Program Stop running due to low number of obs"*/
proc sort data = a;
by id;
run;
proc sort data = b;
by id;
run;

data want;
merge a (in=x) b(in=y);
by id;
a = x;
b = y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 07:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911072#M359258</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-10T07:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911073#M359259</link>
      <description>&lt;P&gt;Use either the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0hp2evpgqvfsfn1u223hh9ubv3g.htm" target="_blank" rel="noopener"&gt;ABORT&lt;/A&gt;&amp;nbsp;data step statement, or the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0f7j2zr6z71nqn1fpefnmulzazf.htm" target="_blank" rel="noopener"&gt;%ABORT&lt;/A&gt;&amp;nbsp;macro statement.&lt;/P&gt;
&lt;P&gt;Use the ABEND option, and specify a non-zero exit code to notify your scheduler about the condition, so it can react properly (schedulers can send notification emails).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the search option here in the communities, or do a Google search for "SAS communities send email from SAS". We have a ton of posts about this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911073#M359259</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-10T08:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911077#M359261</link>
      <description>&lt;P&gt;Can you please show the full code that stop run the program ? (About send email I know how to do it)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911077#M359261</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-10T08:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911078#M359262</link>
      <description>&lt;P&gt;I run this code&amp;nbsp; and it is working well (Program stop running as required) but why do I get an error??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also where and how should I add the send email?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FILENAME mail EMAIL &lt;BR /&gt;TO=("ABC@gmail.com")&lt;BR /&gt;FROM='ABC@gmail.com&amp;gt;'&lt;BR /&gt;SUBJECT="Stop execute message "&lt;BR /&gt;CONTENT_TYPE="text/html" encoding="utf-8";&lt;BR /&gt;ODS LISTING CLOSE;&lt;BR /&gt;ODS HTML BODY=mail;&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;/*conditionally stop SAS code execution*/
/*conditionally stop SAS code execution*/
/*conditionally stop SAS code execution*/
Data A;
Input ID Name$ Height;
cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

Data B;
Input ID Name$ Weight;
cards;
2 A 2
4 B 3
7 D 5
;
run;

proc sql noprint;
select count(*) as nr_A into :nr_A
from A
;
quit;
%put &amp;amp;nr_A;
proc sql noprint;
select count(*) as nr_B  into :nr_B
from B
;
quit;
%put &amp;amp;nr_B;


/*Here I want to add condition to code execution*/
/*IF &amp;amp;nr_A&amp;lt;5 OR &amp;amp;nr_B&amp;lt;5 then STOP execustion and send email "Program Stop running due to low number of obs"*/
%macro runquit;
; run; quit;
%if &amp;amp;nr_A&amp;lt;5 OR &amp;amp;nr_B&amp;lt;5  %then %do;
%abort;
%end;

%else %Do;
proc sort data = a;
by id;
run;
proc sort data = b;
by id;
run;

data want;
merge a (in=x) b(in=y);
by id;
a = x;
b = y;
run;
%end;
%mend runquit;
%runquit
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911078#M359262</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-10T08:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911122#M359284</link>
      <description>&lt;P&gt;Since SAS 9.4, you do not need a macro definition for a simple %IF-%THEN.&lt;/P&gt;
&lt;P&gt;You can do this in "open code":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;nr_A. &amp;lt; 5 or &amp;amp;nr_B. &amp;lt; 5
%then %do;
  /* put your email code here */
  %abort abend;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 13:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911122#M359284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-10T13:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: conditionally stop SAS code execution and send email with notification</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911128#M359286</link>
      <description>&lt;P&gt;Below one option if you just want to send the email and then skip any subsequent statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A;
  Input ID Name$ Height;
  cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

Data B;
  Input ID Name$ Weight;
  cards;
2 A 2
4 B 3
7 D 5
;
run;

data _null_;
  call symputx('nr_a',nobs_a);
  call symputx('nr_b',nobs_b);
  stop;
  set a nobs=nobs_a;
  set b nobs=nobs_b;
run;

%put &amp;amp;=nr_a &amp;amp;=nr_b;

%macro demo();
  %if &amp;amp;nr_A&amp;lt;5 OR &amp;amp;nr_B&amp;lt;5 %then
    %do;
      /* here your send email code */
      
      /* goto end of program */
      %goto done;

    %end;

  proc sort data = a;
    by id;
  run;

  proc sort data = b;
    by id;
  run;

  data want;
    merge a (in=x) b(in=y);
    by id;
    a = x;
    b = y;
  run;

  %done:

%mend;
%demo();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 13:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditionally-stop-SAS-code-execution-and-send-email-with/m-p/911128#M359286</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-10T13:53:51Z</dc:date>
    </item>
  </channel>
</rss>

