<?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: Not send email if error exist in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374295#M65286</link>
    <description>&lt;P&gt;To select the error messages / count warning messages - you will need to save the log in file,&lt;/P&gt;
&lt;P&gt;read it, locate the messages (use index or find function) and save them in a flat file to be attached to the email.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A new skeleton should look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let SYscc=0;
filename mylog '...any name.log';
proc printto file=mylog; run;  /* open and start keep log */

    ==== your code enter here without any email code ====
%let myrc = &amp;amp;syscc;
%proc printto; run;   /* close the log file */

/* checking the log */
filename msg '...any name.txt';
data null;
  retain count_warn 0;
   infile mylog  end=eov;
   file msg;
   input a_line $200;  /* adapt to max log line */
   if index(a_line, 'ERROR') then put a_line;
   if index(a_line,'Warning')  then count_warn +1;
   if eov then put 'WARNING ' count_warn=;
run;
   

%macro check;
      %if %eval(&amp;amp;myrc) LE 4 %then %do;
            ==== enter code for email when no errors ====
      %end;
     %else %do;
           ==== enter code for email when error occured ====
              === with attached file MSG ===
    %end;
%mend check;
%check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may prefer check &amp;amp;myrc to 0, then even one warning will treat it as having ERROR, or&lt;/P&gt;
&lt;P&gt;you may send &lt;U&gt;&lt;STRONG&gt;both&lt;/STRONG&gt; &lt;/U&gt;emails when &amp;amp;myrc=4, as there are only warnings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jul 2017 17:46:01 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-07-09T17:46:01Z</dc:date>
    <item>
      <title>Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374231#M65280</link>
      <description>&lt;P&gt;Hello Expert.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My requirement is to display error message in the template of email along with total individual observation for dataset one and two.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is an error in the program, it should not transmit output &amp;nbsp;to request user (&lt;SPAN&gt;abc@gmail.com). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In stead, it will send email with log file to programmer "bcd@gmail.com" with list of error message in the template.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Email Template should be like below&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please see attached file for your daily report&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Total number of observation for dataset one=5&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Total number of observation for dataset one=19&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;List of error&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ERROR:- merging issue &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Total warning message :-&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can anybody help me how to create template like below from below sample dataset.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Program&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let run=&amp;amp;sysdate;&lt;BR /&gt;proc printto&lt;BR /&gt; log="/C:/Log/&amp;amp;run._ONE..log" New;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;INPUT NAME $ SEX $ AGE Height WEIGHT;&lt;BR /&gt;datalines;&lt;BR /&gt;STEVE M 41 74 170&lt;BR /&gt;ROCKY M 42 68 166&lt;BR /&gt;KURT M 39 72 167&lt;BR /&gt;DEBORAH F 30 66 124&lt;BR /&gt;JACQUEL F 33 66 115&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data two;&lt;BR /&gt;set sashelp.class;run;&lt;/P&gt;
&lt;P&gt;data three;&lt;BR /&gt;set one two;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%let OutPut=/C:/test/output/;&lt;BR /&gt;ods tagsets.excelxp FILE = "&amp;amp;Output/Test_&amp;amp;run..xls";&lt;BR /&gt;proc print data= three ;&lt;BR /&gt; title "Dataset three Output" ;&lt;BR /&gt;run;&lt;BR /&gt;ods tagsets.excelxp close;&lt;/P&gt;
&lt;P&gt;proc printto;run;&lt;BR /&gt;*Begin email code;&lt;BR /&gt;FILENAME myemail2 EMAIL from=("abch@gmail.com")&lt;BR /&gt; to=("abc@gmail.com")&lt;BR /&gt; Subject = "An email with attachment sent from SAS"&lt;BR /&gt; Attach = ("/C:/Output/Test_&amp;amp;run..xls"&lt;BR /&gt; "/C:/log/&amp;amp;run._TEST..log");&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;file myemail2;&lt;BR /&gt;/ /put "Please see attached file for your daily report."&lt;BR /&gt;/ / "Thank you and have a great day."&lt;BR /&gt;/ / " "&lt;BR /&gt;/ /"Sincerely";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 07:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374231#M65280</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-09T07:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374237#M65281</link>
      <description>&lt;P&gt;Use next skeleton in your program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let SYscc=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ==== your code enter here without any email code ====&lt;/P&gt;
&lt;P&gt;&amp;nbsp;%let myrc = &amp;amp;syscc;&lt;/P&gt;
&lt;P&gt;%macro check;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %if %eval(&amp;amp;myrc) LE 4 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ==== enter code for email when no errors ====&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%else %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;==== enter code for email when error occured ====&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;%mend check;&lt;/P&gt;
&lt;P&gt;%check;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 14:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374237#M65281</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-09T14:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374263#M65282</link>
      <description>&lt;P&gt;I'd rather use &amp;amp;syscc, as &amp;amp;sysrc holds the return code of the last system command, not the state of the SAS session.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 14:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374263#M65282</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-09T14:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374266#M65283</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, I agree with you. It was my typo.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 14:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374266#M65283</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-09T14:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374293#M65285</link>
      <description>&lt;P&gt;Thank you very much for your support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I display the error message in the email template.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Along with this, I want to count the total warning message to display on the template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks once again&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 17:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374293#M65285</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-09T17:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374295#M65286</link>
      <description>&lt;P&gt;To select the error messages / count warning messages - you will need to save the log in file,&lt;/P&gt;
&lt;P&gt;read it, locate the messages (use index or find function) and save them in a flat file to be attached to the email.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A new skeleton should look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let SYscc=0;
filename mylog '...any name.log';
proc printto file=mylog; run;  /* open and start keep log */

    ==== your code enter here without any email code ====
%let myrc = &amp;amp;syscc;
%proc printto; run;   /* close the log file */

/* checking the log */
filename msg '...any name.txt';
data null;
  retain count_warn 0;
   infile mylog  end=eov;
   file msg;
   input a_line $200;  /* adapt to max log line */
   if index(a_line, 'ERROR') then put a_line;
   if index(a_line,'Warning')  then count_warn +1;
   if eov then put 'WARNING ' count_warn=;
run;
   

%macro check;
      %if %eval(&amp;amp;myrc) LE 4 %then %do;
            ==== enter code for email when no errors ====
      %end;
     %else %do;
           ==== enter code for email when error occured ====
              === with attached file MSG ===
    %end;
%mend check;
%check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may prefer check &amp;amp;myrc to 0, then even one warning will treat it as having ERROR, or&lt;/P&gt;
&lt;P&gt;you may send &lt;U&gt;&lt;STRONG&gt;both&lt;/STRONG&gt; &lt;/U&gt;emails when &amp;amp;myrc=4, as there are only warnings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 17:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/374295#M65286</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-09T17:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375031#M65320</link>
      <description>&lt;P&gt;Thank you very much Shumel for your great help.&lt;/P&gt;
&lt;P&gt;I tried to implement that changes which you suggested. However, I donot know how to display it in the email template.&lt;/P&gt;
&lt;P&gt;Also request to check the code once again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks once again in advane for your support&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Program&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let run=&amp;amp;sysdate;&lt;BR /&gt;%let SYscc=0;&lt;BR /&gt;filename mylog "C:/&amp;amp;run._jacob..log";&lt;BR /&gt;proc printto file=mylog; run; /* open and start keep log */&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input NAME $ SEX $ AGE Height WEIGHT;&lt;BR /&gt;datalines;&lt;BR /&gt;STEVE M 41 74 170&lt;BR /&gt;ROCKY M 42 68 166&lt;BR /&gt;KURT M 39 72 167&lt;BR /&gt;DEBORAH F 30 66 124&lt;BR /&gt;JACQUELI F 33 66 115&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%let OutPut=C:/;&lt;BR /&gt;ods tagsets.excelxp FILE = "&amp;amp;Output/Test_&amp;amp;run..xls"&lt;BR /&gt;style=analysis&lt;BR /&gt; options (embedded_titles='yes'&lt;BR /&gt; embedded_footnotes='no'&lt;BR /&gt; orientation='landscape'&lt;BR /&gt; fittopage='yes'&lt;BR /&gt; missing_align='center'&lt;BR /&gt; autofit_height='yes'&lt;BR /&gt; autofilter='yes'&lt;BR /&gt; row_repeat='1'&lt;BR /&gt; sheet_name='Data'&lt;BR /&gt; sheet_interval='None');;&lt;BR /&gt;proc print data= one ;&lt;BR /&gt; title "jacob Output" ;&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;ods tagsets.excelxp close;&lt;/P&gt;
&lt;P&gt;%let myrc = &amp;amp;syscc;&lt;BR /&gt;proc printto; run; /* close the log file */&lt;/P&gt;
&lt;P&gt;/* checking the log */&lt;BR /&gt;filename msg 'C:/help.txt';&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; retain count_warn 0;&lt;BR /&gt; infile mylog end=eov;&lt;BR /&gt; file msg;&lt;BR /&gt; input a_line $200; /* adapt to max log line */&lt;BR /&gt; if index(a_line, 'ERROR') then put a_line;&lt;BR /&gt; if index(a_line,'Warning') then count_warn +1;&lt;BR /&gt; if eov then put 'WARNING ' count_warn=;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;*Begin email code;&lt;BR /&gt;%let myrc = &amp;amp;syscc;&lt;BR /&gt;%macro check;&lt;BR /&gt; %if %eval(&amp;amp;myrc) LE 4 %then %do;&lt;BR /&gt; FILENAME myemail2 EMAIL from=("abc@gmail.com")&lt;BR /&gt; to=("abc@gmail.com")&lt;BR /&gt; Subject = "Email without any error"&lt;BR /&gt; Attach = ("C:/Test_&amp;amp;run..xls"&lt;BR /&gt; "C:/&amp;amp;run._jacob..log");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;file myemail2;&lt;BR /&gt;Put "Dear X"&lt;BR /&gt;/ /put " "&lt;BR /&gt;/ /put "Please see attached log file for your daily report with no error."&lt;BR /&gt;/ / "Thank you and have a great day.";&lt;BR /&gt;run; &lt;BR /&gt; %end;&lt;BR /&gt; %else %do;&lt;BR /&gt; FILENAME myemail2 EMAIL from=("abc@gmail.com")&lt;BR /&gt; to=("abc@gmail.com")&lt;BR /&gt; Subject = "Email with error"&lt;BR /&gt; Attach = ("C:/&amp;amp;run._jacob..log");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;file myemail2;&lt;BR /&gt;Put "Dear X"&lt;BR /&gt;/ /put " "&lt;BR /&gt;/ /put "Please see attached log file for your daily report with error."&lt;BR /&gt;/ / "Thank you and have a great day.";&lt;BR /&gt;run; &lt;BR /&gt; %end;&lt;BR /&gt;%mend check;&lt;BR /&gt;%check;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 16:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375031#M65320</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-11T16:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375051#M65321</link>
      <description>&lt;P&gt;Please see my remarks in attached msword documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have issues with the output mail, please attach the &lt;STRONG&gt;log&lt;/STRONG&gt; and the &lt;STRONG&gt;mail&lt;/STRONG&gt; you got.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 17:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375051#M65321</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-11T17:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375426#M65331</link>
      <description>&lt;P&gt;Thank you Shmuel once again for your great support. Based on your suggestion, I have rectified the program and it is working fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you asked whether&amp;nbsp;to attach the whole log file or only the warnings during email alert, I need both attached log file and warning/error message in the email template. If not possible, at lease warning and error should be displayed in the body of email like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Subject = Email with error&lt;BR /&gt; &lt;STRONG&gt;&lt;EM&gt;Dear X"&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;Please see log file for your daily report with error."&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;lt;I need errror and warning message to be available here e.g.&amp;gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;ERROR: ORACLE connection error: ORA-12154: TNS:could not resolve the connect identifier specified.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Total number of warning message=6&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;Thank you and have a great day.&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attach the log file for reference. In the program, I have added connect by procedure to access one table to get ORA- error so that I can explain my requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in adance&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 17:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375426#M65331</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-12T17:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375479#M65332</link>
      <description>&lt;P&gt;I have addapted the checking log code to create 2 macro variables -&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (1) &amp;nbsp;ERR_LINE &amp;nbsp; &amp;nbsp;- is the ERROR message and&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (2) &amp;nbsp;WARN_LINE - is the count of warnings.&lt;/P&gt;
&lt;P&gt;You can include those macro variables in the body of your letter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* checking the log */
***filename msg 'C:/help.txt';   /* use macro vars instead the msg file */
data _null_;
retain count_warn 0;
infile mylog end=eov;
***file msg;
input a_line $200;    /* adapt to max log line */
if index(a_line, 'ERROR') then
   call symout('ERR_LINE, trim(a_line));
if index(a_line,'Warning') then count_warn +1;
if eov then 
   call symput('Warn_line ', cat('there are ',left(count_warn), '  warnings');
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe you will need declare those macro variables as %global.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375479#M65332</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-12T19:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375594#M65340</link>
      <description>&lt;P&gt;Thanks a million Shmuel for your support.&lt;/P&gt;
&lt;P&gt;One query , When I use the macro variable in the body of email, why it is not resolved. Is it like that I made some mistake in the program. Attaching it for reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Along with this, Why the log file only show repetition of output after changing the program, not the fully generated one from text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I request you to guide.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 09:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375594#M65340</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-13T09:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375604#M65341</link>
      <description>&lt;P&gt;Out statements accepts either a variable name or a literal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put  &amp;amp;warn_line.;
put  &amp;amp;err_line.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;into:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put  "&amp;amp;warn_line.";
put  "&amp;amp;err_line.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 10:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375604#M65341</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-13T10:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375607#M65342</link>
      <description>&lt;P&gt;The file log.docx doesn't seem to show the log of the program.&lt;/P&gt;
&lt;P&gt;I couldn't find any put statemants or a loop to create it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to locate what creates this output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you have overwitten the log with some output reporting ?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 10:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375607#M65342</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-13T10:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375633#M65345</link>
      <description>&lt;P&gt;The error and warning message resolve to blank even though they are available in the program.&lt;/P&gt;
&lt;P&gt;I think there is an issue with proc printto and filename statement because when I check the log file, it contains only attached output with out any warning/error message. Therefore, the macro variable resolve it to blank. (attached log file for your reference)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;filename mylog "/proj/sastmp/pvdm/99_TEST_QC/Test/ANA_028/&amp;amp;run._ANA_028.log";&lt;BR /&gt;proc printto file=mylog new; run;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 11:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375633#M65345</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-13T11:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375647#M65346</link>
      <description>&lt;P&gt;You need to execute that code at the beginning of your program; only subsequent code will put its log there, code that has already run won't show.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 11:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375647#M65346</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-13T11:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375651#M65347</link>
      <description>&lt;P&gt;Please attach your code using the {i} icon. It will be easier to read and to locate errors.&lt;/P&gt;
&lt;P&gt;Attaching a .txt file is not very friendly and less usefull.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 11:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375651#M65347</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-13T11:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375674#M65351</link>
      <description>&lt;PRE&gt;%let run=&amp;amp;sysdate;
%let SYscc=0;
filename mylog "/C:/&amp;amp;run._test.log";
proc printto file=mylog new; 
run; /* open and start keep log */
%global ERR_LINE WARN_LINE;
data one;
input NAME $ SEX $ AGE Height WEIGHT;
datalines;
STEVE M 41 74 170
ROCKY M 42 68 166
KURT M 39 72 167
DEBORAH F 30 66 124
JACQUELI F 33 66 115
;
run;
/*added coded only to test error and warning msg*/
proc sql;
        connect to oracle as EXT1 (user="&amp;amp;User." orapw="&amp;amp;OraPw." path="&amp;amp;Path.");
            create table work.abc as
                Select * from connection to EXT1
(select * from emp
);
disconnect from ext1;
quit;

%let OutPut=/C:/;
ods tagsets.excelxp FILE = "&amp;amp;Output/Test_&amp;amp;run.xls"
style=analysis
	options (embedded_titles='yes'
			 embedded_footnotes='no'
			 orientation='landscape'
			 fittopage='yes'
			 missing_align='center'
			 autofit_height='yes'
			 autofilter='yes'
			 row_repeat='1'
			 sheet_name='Data'
			 sheet_interval='None');
proc print data= one ;
   title "test Output" ;
run;
ods tagsets.excelxp close;			 
 		 
%let myrc = &amp;amp;syscc;
proc printto log=log; run; /* close the log file */
/* checking the log */
*filename msg '/proj/sastmp/pvdm/99_TEST_QC/help.txt';
data _null_;
retain count_warn 0;
infile mylog end=eov;
***file msg;
input a_line $2000;    /* adapt to max log line */
if index(a_line, 'ERROR') then 
   call symput('ERR_LINE', trim(a_line));
if index(a_line,'Warning') then count_warn +1;
if eov then 
   call symput('Warn_line', cat('there are ',left(count_warn), '  warnings'));
run;
*Begin email code;
%put "&amp;amp;warn_line.";
%put "&amp;amp;err_line.";
%macro check;
%if %eval(&amp;amp;myrc) LE 4 %then %do;
FILENAME myemail2 EMAIL from=("abc@gmail.com")
 to=("abc@gmail.com")
 Subject = "SAS without any error"
  Attach = ("/C:/Test_&amp;amp;run..xls"
			"/C:/&amp;amp;run._test.log");
data _null_;
file myemail2;
Put "Dear X";
put "  ";
put "Report with no error";
run; 
%end;
%else %do;
 FILENAME myemail2 EMAIL from=("abc@gmail.com")
 to=("abc@gmail.com")
 Subject = "SAS with error"
 Attach = ("/C:/&amp;amp;run._test.log");
data _null_;
file myemail2;
Put "Dear X";
put  "&amp;amp;warn_line.";
put  "&amp;amp;err_line.";
put "Report with error.";
run; 
%end;
%mend check;
%check;&lt;/PRE&gt;
&lt;P&gt;Please have a look .&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 12:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375674#M65351</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-13T12:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375681#M65354</link>
      <description>&lt;P&gt;1) Change line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log=log; run; /* close the log file */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; into &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto; run; /* close the log file */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) &amp;nbsp;Checking the log:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;As there is a check for strings "ERROR" and "Warning" - I hope you may have them in log, given by sas only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope that will finally give you the desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 13:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375681#M65354</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-13T13:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Not send email if error exist</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375939#M65368</link>
      <description>&lt;P&gt;Thanks Shmuel for your great help and guidance. The issue is still there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will try with some other program.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 07:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Not-send-email-if-error-exist/m-p/375939#M65368</guid>
      <dc:creator>Abraham</dc:creator>
      <dc:date>2017-07-14T07:36:15Z</dc:date>
    </item>
  </channel>
</rss>

