<?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: send email if error or warning in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979006#M378715</link>
    <description>&lt;P&gt;Thanks so much,&lt;/P&gt;
&lt;P&gt;I have some questions please-&lt;/P&gt;
&lt;P&gt;Here is the code I run based on your feedback&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where should I write my email address???&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should I located this code -&lt;/P&gt;
&lt;P&gt;proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;in top of program??&lt;/P&gt;
&lt;P&gt;I run the coe and get error-&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access /usr/local/SAS/Config/Lev1/LabRet/email.dat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* save your sas code 's LOG  into a file*/
proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;
run;

/**My program code**/
data cars;
set sashelp.cars;
Run;
proc sql;
create table want as
select  make,
        min(invoice) as min_invoice,
        max(invoice) as max_invoice,
		median(invoice) as median_invoice,
		count(disinct  type_ as distinct_types
from cars
group by make
;
quit;



proc printto log=log;
run;

/*parse this LOG file and check it is ERROR or WARNING*/
%let error=no;
%let warning=no;
data _null_;
infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log";
input;
if _infile_ =: 'ERROR' then call symputx('error','yes');
if _infile_ =: 'WARNING' then call symputx('warning','yes');
run;


/*make a macro to send your e-mail or not.*/
%macro email;
data _null_;
file email;
%if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;
%else %if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;
%else %if &amp;amp;error.=yes and &amp;amp;warning.=yes  %then %do; put 'there is an error and warning .'; %end;
run;
%mend;
%email&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log with the error-&lt;/P&gt;
&lt;P&gt;1 The SAS System 14:21 Tuesday, November 18, 2025&lt;/P&gt;
&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Program';&lt;BR /&gt;4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';&lt;BR /&gt;5 %LET _CLIENTPROJECTPATH='';&lt;BR /&gt;6 %LET _CLIENTPROJECTPATHHOST='';&lt;BR /&gt;7 %LET _CLIENTPROJECTNAME='';&lt;BR /&gt;8 %LET _SASPROGRAMFILE='';&lt;BR /&gt;9 %LET _SASPROGRAMFILEHOST='';&lt;BR /&gt;10 &lt;BR /&gt;11 ODS _ALL_ CLOSE;&lt;BR /&gt;12 OPTIONS DEV=SVG;&lt;BR /&gt;13 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;14 %macro HTML5AccessibleGraphSupported;&lt;BR /&gt;15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;&lt;BR /&gt;16 %mend;&lt;BR /&gt;17 FILENAME EGHTML TEMP;&lt;BR /&gt;18 ODS HTML5(ID=EGHTML) FILE=EGHTML&lt;BR /&gt;19 OPTIONS(BITMAP_MODE='INLINE')&lt;BR /&gt;20 %HTML5AccessibleGraphSupported&lt;BR /&gt;21 ENCODING='utf-8'&lt;BR /&gt;22 STYLE=HTMLBlue&lt;BR /&gt;23 NOGTITLE&lt;BR /&gt;24 NOGFOOTNOTE&lt;BR /&gt;25 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;26 ;&lt;BR /&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;27 &lt;BR /&gt;28 /* save your sas code 's LOG into a file*/&lt;BR /&gt;29 proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;&lt;BR /&gt;30 run;&lt;/P&gt;
&lt;P&gt;NOTE: PROCEDURE PRINTTO used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;49 &lt;BR /&gt;50 /*parse this LOG file and check it is ERROR or WARNING*/&lt;BR /&gt;51 %let error=no;&lt;BR /&gt;52 %let warning=no;&lt;BR /&gt;53 data _null_;&lt;BR /&gt;54 infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log";&lt;BR /&gt;55 input;&lt;BR /&gt;56 if _infile_ =: 'ERROR' then call symputx('error','yes');&lt;BR /&gt;57 if _infile_ =: 'WARNING' then call symputx('warning','yes');&lt;BR /&gt;58 run;&lt;/P&gt;
&lt;P&gt;NOTE: The infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" is:&lt;BR /&gt;Filename=/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log,&lt;BR /&gt;Owner Name=udclk79,&lt;BR /&gt;Group Name=gr_il_sas_users_labret,&lt;BR /&gt;Access Permission=-rw-r--r--,&lt;BR /&gt;Last Modified=18Nov2025:14:35:46,&lt;BR /&gt;File Size (bytes)=1902&lt;/P&gt;
&lt;P&gt;NOTE: 53 records were read from the infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log".&lt;BR /&gt;The minimum record length was 0.&lt;BR /&gt;The maximum record length was 133.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;59 &lt;BR /&gt;3 The SAS System 14:21 Tuesday, November 18, 2025&lt;/P&gt;
&lt;P&gt;60 &lt;BR /&gt;61 /*make a macro to send your e-mail or not.*/&lt;BR /&gt;62 %macro email;&lt;BR /&gt;63 data _null_;&lt;BR /&gt;64 file email;&lt;BR /&gt;65 %if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;&lt;BR /&gt;66 %else %if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;&lt;BR /&gt;67 %else %if &amp;amp;error.=yes and &amp;amp;warning.=yes %then %do; put 'there is an error and warning .'; %end;&lt;BR /&gt;68 run;&lt;BR /&gt;69 %mend;&lt;BR /&gt;70 %email&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access /usr/local/SAS/Config/Lev1/LabRet/email.dat.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;71 &lt;BR /&gt;72 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;73 %LET _CLIENTPROCESSFLOWNAME=;&lt;BR /&gt;74 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;75 %LET _CLIENTPROJECTPATHHOST=;&lt;BR /&gt;76 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;77 %LET _SASPROGRAMFILE=;&lt;BR /&gt;78 %LET _SASPROGRAMFILEHOST=;&lt;BR /&gt;79 &lt;BR /&gt;80 ;*';*";*/;quit;run;&lt;BR /&gt;81 ODS _ALL_ CLOSE;&lt;BR /&gt;82 &lt;BR /&gt;83 &lt;BR /&gt;84 QUIT; RUN;&lt;BR /&gt;85&lt;/P&gt;</description>
    <pubDate>Tue, 18 Nov 2025 12:39:28 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2025-11-18T12:39:28Z</dc:date>
    <item>
      <title>send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/978999#M378711</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want&amp;nbsp; to run a sas program and -&lt;/P&gt;
&lt;P&gt;1-create a binary macro variable that get value 1 if program had error&lt;/P&gt;
&lt;P&gt;2-create a binary macro variable that get value 1 if program had warning&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;send automatic email via sas to my email (Only in case of error or warning) and say one of these 3 options:&lt;/P&gt;
&lt;P&gt;"Error occured&amp;nbsp; during run the code"&lt;/P&gt;
&lt;P&gt;"Warning occured&amp;nbsp; during run the code"&lt;/P&gt;
&lt;P&gt;"Error and Warning&amp;nbsp; occured&amp;nbsp; during run the code"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example lets say I run this code that has error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars;
set sashelp.cars;
Run;

proc sql;
create table want as
select  make,
        min(invoice) as min_invoice,
        max(invoice) as max_invoice,
		median(invoice) as median_invoice,
		count(disinct  type_ as distinct_types
from cars
group by make
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Nov 2025 08:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/978999#M378711</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-11-18T08:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979001#M378712</link>
      <description>Check the &amp;amp;SYSCC automatic macro variable. You need to do this after each step, as an ERROR will override any WARNING.</description>
      <pubDate>Tue, 18 Nov 2025 09:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979001#M378712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-11-18T09:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979002#M378713</link>
      <description>&lt;P&gt;1)Firstly save your sas code 's LOG&amp;nbsp; into a file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto file='c:\temp\x.log' new;
run;
/*.......your code here...........*/
proc printto;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2)Secondly, parse this LOG file and check it is ERROR or WARNING :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let error=no;&lt;BR /&gt;%let warning=no;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _null_;
infile 'c:\temp\x.log';
input;
if _infile_ =: 'ERROR' then call symputx('error','yes');
if _infile_ =: 'WARNING' then call symputx('warning','yes');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3)Thirdly, make a macro to send your e-mail or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro email;
data _null_;
file email;

%if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;
%else %if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;
%else %if &amp;amp;error.=yes and &amp;amp;warning.=yes  %then %do; put 'there is an error and warning .'; %end;

run;
%mend;

%email&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 09:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979002#M378713</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-11-18T09:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979004#M378714</link>
      <description>&lt;P&gt;The following SAS Note has an example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/32/187.html" target="_blank"&gt;https://support.sas.com/kb/32/187.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 11:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979004#M378714</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-11-18T11:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979006#M378715</link>
      <description>&lt;P&gt;Thanks so much,&lt;/P&gt;
&lt;P&gt;I have some questions please-&lt;/P&gt;
&lt;P&gt;Here is the code I run based on your feedback&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where should I write my email address???&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should I located this code -&lt;/P&gt;
&lt;P&gt;proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;in top of program??&lt;/P&gt;
&lt;P&gt;I run the coe and get error-&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access /usr/local/SAS/Config/Lev1/LabRet/email.dat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* save your sas code 's LOG  into a file*/
proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;
run;

/**My program code**/
data cars;
set sashelp.cars;
Run;
proc sql;
create table want as
select  make,
        min(invoice) as min_invoice,
        max(invoice) as max_invoice,
		median(invoice) as median_invoice,
		count(disinct  type_ as distinct_types
from cars
group by make
;
quit;



proc printto log=log;
run;

/*parse this LOG file and check it is ERROR or WARNING*/
%let error=no;
%let warning=no;
data _null_;
infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log";
input;
if _infile_ =: 'ERROR' then call symputx('error','yes');
if _infile_ =: 'WARNING' then call symputx('warning','yes');
run;


/*make a macro to send your e-mail or not.*/
%macro email;
data _null_;
file email;
%if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;
%else %if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;
%else %if &amp;amp;error.=yes and &amp;amp;warning.=yes  %then %do; put 'there is an error and warning .'; %end;
run;
%mend;
%email&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log with the error-&lt;/P&gt;
&lt;P&gt;1 The SAS System 14:21 Tuesday, November 18, 2025&lt;/P&gt;
&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Program';&lt;BR /&gt;4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';&lt;BR /&gt;5 %LET _CLIENTPROJECTPATH='';&lt;BR /&gt;6 %LET _CLIENTPROJECTPATHHOST='';&lt;BR /&gt;7 %LET _CLIENTPROJECTNAME='';&lt;BR /&gt;8 %LET _SASPROGRAMFILE='';&lt;BR /&gt;9 %LET _SASPROGRAMFILEHOST='';&lt;BR /&gt;10 &lt;BR /&gt;11 ODS _ALL_ CLOSE;&lt;BR /&gt;12 OPTIONS DEV=SVG;&lt;BR /&gt;13 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;14 %macro HTML5AccessibleGraphSupported;&lt;BR /&gt;15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;&lt;BR /&gt;16 %mend;&lt;BR /&gt;17 FILENAME EGHTML TEMP;&lt;BR /&gt;18 ODS HTML5(ID=EGHTML) FILE=EGHTML&lt;BR /&gt;19 OPTIONS(BITMAP_MODE='INLINE')&lt;BR /&gt;20 %HTML5AccessibleGraphSupported&lt;BR /&gt;21 ENCODING='utf-8'&lt;BR /&gt;22 STYLE=HTMLBlue&lt;BR /&gt;23 NOGTITLE&lt;BR /&gt;24 NOGFOOTNOTE&lt;BR /&gt;25 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;26 ;&lt;BR /&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;27 &lt;BR /&gt;28 /* save your sas code 's LOG into a file*/&lt;BR /&gt;29 proc printto log="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" new;&lt;BR /&gt;30 run;&lt;/P&gt;
&lt;P&gt;NOTE: PROCEDURE PRINTTO used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;49 &lt;BR /&gt;50 /*parse this LOG file and check it is ERROR or WARNING*/&lt;BR /&gt;51 %let error=no;&lt;BR /&gt;52 %let warning=no;&lt;BR /&gt;53 data _null_;&lt;BR /&gt;54 infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log";&lt;BR /&gt;55 input;&lt;BR /&gt;56 if _infile_ =: 'ERROR' then call symputx('error','yes');&lt;BR /&gt;57 if _infile_ =: 'WARNING' then call symputx('warning','yes');&lt;BR /&gt;58 run;&lt;/P&gt;
&lt;P&gt;NOTE: The infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log" is:&lt;BR /&gt;Filename=/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log,&lt;BR /&gt;Owner Name=udclk79,&lt;BR /&gt;Group Name=gr_il_sas_users_labret,&lt;BR /&gt;Access Permission=-rw-r--r--,&lt;BR /&gt;Last Modified=18Nov2025:14:35:46,&lt;BR /&gt;File Size (bytes)=1902&lt;/P&gt;
&lt;P&gt;NOTE: 53 records were read from the infile "/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log".&lt;BR /&gt;The minimum record length was 0.&lt;BR /&gt;The maximum record length was 133.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;59 &lt;BR /&gt;3 The SAS System 14:21 Tuesday, November 18, 2025&lt;/P&gt;
&lt;P&gt;60 &lt;BR /&gt;61 /*make a macro to send your e-mail or not.*/&lt;BR /&gt;62 %macro email;&lt;BR /&gt;63 data _null_;&lt;BR /&gt;64 file email;&lt;BR /&gt;65 %if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;&lt;BR /&gt;66 %else %if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;&lt;BR /&gt;67 %else %if &amp;amp;error.=yes and &amp;amp;warning.=yes %then %do; put 'there is an error and warning .'; %end;&lt;BR /&gt;68 run;&lt;BR /&gt;69 %mend;&lt;BR /&gt;70 %email&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access /usr/local/SAS/Config/Lev1/LabRet/email.dat.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;71 &lt;BR /&gt;72 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;73 %LET _CLIENTPROCESSFLOWNAME=;&lt;BR /&gt;74 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;75 %LET _CLIENTPROJECTPATHHOST=;&lt;BR /&gt;76 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;77 %LET _SASPROGRAMFILE=;&lt;BR /&gt;78 %LET _SASPROGRAMFILEHOST=;&lt;BR /&gt;79 &lt;BR /&gt;80 ;*';*";*/;quit;run;&lt;BR /&gt;81 ODS _ALL_ CLOSE;&lt;BR /&gt;82 &lt;BR /&gt;83 &lt;BR /&gt;84 QUIT; RUN;&lt;BR /&gt;85&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 12:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979006#M378715</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-11-18T12:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979007#M378716</link>
      <description>&lt;P&gt;I&amp;nbsp; saw this example and it is working 100%&lt;/P&gt;
&lt;P&gt;In this example ther is no action of&amp;nbsp; saving Log file .&lt;/P&gt;
&lt;P&gt;What is the purpose of saving the Log file?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you recommend to add the Log file as attach file to the email?&lt;/P&gt;
&lt;P&gt;Or print the Log file in the email body??(Not good if log is very big)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   data a;
     input x $ y;
   cards;
   a 1
   b 2
   c 3
   ;
 Run;


proc means sum;
var x y;
run;


%macro send_mail;
   filename mymail email to=('xxx.xxx@xxx.xxx.xxx') subject='סיכום אם הייתה שגיאה בריצה'  encoding='utf-8';
     %if &amp;amp;syscc&amp;gt;0 %then %do;
       data _null_;
         file mymail;
         put 'התרחשה שגיאה בהרצה של תוכנית סאס';
       run;
     %end;
     %else %do;
       data _null_;
         file mymail;
         put 'הריצה בוצעה ללא שגיאות';
       run;
     %end;
     %let syscc=0;
   %mend;
   %send_mail
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 12:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979007#M378716</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-11-18T12:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979032#M378719</link>
      <description>&lt;P&gt;This example checks the value of the &amp;amp;syscc macro variable at a step boundary. You could save the log file if you want to see what the actual log message is. Also since each step boundary generates its own &amp;amp;syscc value, you could use the log to check for multiple &amp;amp;syscc values.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 17:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979032#M378719</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-11-18T17:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979033#M378720</link>
      <description>&lt;P&gt;What do you mean by "run a sas program"?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Submit code in Studio or EG&lt;/LI&gt;
&lt;LI&gt;Submit a whole project in EG or flow in Studio&lt;/LI&gt;
&lt;LI&gt;Run a separately saved (.sas file) program in batch mode&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;And do you want to send the notification from within the program/submitted code, or from somewhere "outside" (e.g. shell script)?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 18:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979033#M378720</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-11-18T18:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: send email if error or warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979077#M378730</link>
      <description>&lt;P&gt;You should put your code of sending email in macro %email. My code is just an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;%let log=c:\temp\log.log ;&lt;/STRONG&gt; */usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/RonLog.log;

/* save your sas code 's LOG  into a file*/
&lt;STRONG&gt;proc printto log="&amp;amp;log." new;
run;
&lt;/STRONG&gt;
/**My program code**/
data cars;
set sashelp.cars;
Run;
proc sql;
create table want as
select  make,
        min(invoice) as min_invoice,
        max(invoice) as max_invoice,
		median(invoice) as median_invoice,
		count(disinct  type_ as distinct_types
from cars
group by make
;
quit;

&lt;STRONG&gt;proc printto ;
run;&lt;/STRONG&gt;




/*parse this LOG file and check it is ERROR or WARNING*/
%let error=no;
%let warning=no;
data _null_;
&lt;STRONG&gt;infile "&amp;amp;log.";&lt;/STRONG&gt;
input;
if _infile_ =: 'ERROR' then call symputx('error','yes');
if _infile_ =: 'WARNING' then call symputx('warning','yes');
run;

&lt;STRONG&gt;/*Check macro variable ERROR and WARNING*/
%put &amp;amp;=error. &amp;amp;=warning. ;&lt;/STRONG&gt;






%macro email;
&lt;STRONG&gt;
/****SEND EMAIL****/
/****SEND EMAIL****/
/****SEND EMAIL****/
/****SEND EMAIL****/
FILENAME mail EMAIL 
from="XXX.EXXX@XXXX"
TO=("XXX.EXXX@XXXX")
SUBJECT=" --&amp;amp;last_mon_in_Report_YYMM1.-בקרת ציון כא-דוח לפני פרסום סקור"
encoding='utf-8'  /**To show Hebrew!!!**/
CONTENT_TYPE="text/plain" 
attach=(&amp;amp;path. content_type="excel");
ODS LISTING CLOSE;&lt;/STRONG&gt;
/*ODS HTML BODY=mail;*/

/*
data _null_;
file mail;
put 'היי';
put 'מצורף קובץ בקרה -&amp;amp;last_mon_in_Report_YYMM1.';
put ' ';
put 'בברכה, XXX XXX';
run;
*/
&lt;STRONG&gt;
data _null_;
file mail;

%if &amp;amp;error.=yes %then %do; put 'there is an error.'; %end;
%if &amp;amp;warning.=yes %then %do; put 'there is an warning.'; %end;

run;&lt;/STRONG&gt;
%mend;

%email&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 07:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/send-email-if-error-or-warning/m-p/979077#M378730</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-11-19T07:09:26Z</dc:date>
    </item>
  </channel>
</rss>

