<?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: Sending emails with program updates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638320#M189821</link>
    <description>&lt;P&gt;If you want to have the email include the actual error in the body of the message, then I think you might want to parse the log, looking for errors, warnings, and bad notes.&amp;nbsp; It's a non-trivial task, but of course once you have a %logscan() macro that will email you, you can use it everywhere.&amp;nbsp; Also, there are plenty of %logscan macros in papers and blog posts etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one I like, and there are more mentioned in the comments:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://bi-notes.com/sas-eg-check-the-log/" target="_blank"&gt;https://bi-notes.com/sas-eg-check-the-log/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other option to scanning the log is to just test &amp;amp;syscc, as you are doing, and when you send an email to notify you of an error, attach the log file to the email.&amp;nbsp; Or sometimes you can put a link to the log file in the body of the email, rather than attach it.&amp;nbsp; Even if you do the log scanning and put the error message in the email, nine times out of 10, you end up opening the full log file.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 14:17:30 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2020-04-08T14:17:30Z</dc:date>
    <item>
      <title>Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638295#M189808</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;I have developed a project for my processing of quiet an intensive workload.&lt;/P&gt;&lt;P&gt;I have broken it into 4 separate programs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the very top of my programs I tell SAS to print the log to a specific location.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="location\\Parsing_&amp;amp;date..txt";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;At the end of the program I have.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I would like to do is have SAS check these logs and send me an email if it finds an error in them. I have seen this code online. I would like to augment the below to actually pull what the error is too. I would also like to add another condition to check if the code is still running.&lt;/P&gt;&lt;P&gt;So I would have condition 1 - An error occurred 2 - Code is still running 3 - The job ran to completion&lt;/P&gt;&lt;P&gt;Can anyone provide any advice?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   %macro send_mail;
   filename mymail email 'myemail' subject='Processing';
     %if &amp;amp;syscc&amp;gt;0 %then %do;
       data _null_;
         file mymail;
         put 'An ERROR has occurred in the code';
       run;
     %end;
     %else %do;
       data _null_;
         file mymail;
         put 'The job ran to completion';
       run;
     %end;
   %mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 12:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638295#M189808</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2020-04-08T12:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638310#M189815</link>
      <description>&lt;P&gt;You do not need to check the log; just use the automatic macro variable &amp;amp;SYSCC. If it's not zero, something went wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 12:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638310#M189815</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-08T12:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638311#M189816</link>
      <description>&lt;P&gt;Kurt would this still work even if at the top of my program I'm printing the log to an external area??&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 13:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638311#M189816</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2020-04-08T13:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638312#M189817</link>
      <description>&lt;P&gt;The automatic macro variable &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p11nt7mv7k9hl4n1x9zwkralgq1b.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SYSCC&lt;/A&gt; (follow the link) is independent from where the log is written. It contains the exit code that SAS will return to the parent process when it ends. For a run free of WARNINGs and ERRORs, this is 0.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 13:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638312#M189817</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-08T13:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638315#M189818</link>
      <description>&lt;P&gt;I have a macro written that carries out a procedure n times. I'm printing all from the logs to an external file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following and I'm getting email saying an error has occurred. When I examine the log there is no error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log="Logs\i..txt";
%macro agg(month,final_data);

*My macro steps;

%mend agg;
%agg(temps.apr_20,pmoda.apr_20);

   %macro send_mail;
   filename mymail email 'myemail' subject='Processing';
     %if &amp;amp;SYSCC&amp;gt;0 %then %do;
       data _null_;
         file mymail;
         put 'An ERROR has occurred in the code';
       run;
     %end;
     %else %do;
       data _null_;
         file mymail;
         put 'The job ran to completion';
       run;
     %end;
   %mend;

   %send_mail
proc printto;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 13:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638315#M189818</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2020-04-08T13:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638317#M189819</link>
      <description>&lt;P&gt;Insert&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;syscc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the beginning of your code to see if you enter it in a clean state.&lt;/P&gt;
&lt;P&gt;You can also do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let syscc = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the beginning of your code to reset the macro variable if the non-zero code is caused by something in your autoexec. SYSCC is read and write.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 13:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638317#M189819</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-08T13:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638320#M189821</link>
      <description>&lt;P&gt;If you want to have the email include the actual error in the body of the message, then I think you might want to parse the log, looking for errors, warnings, and bad notes.&amp;nbsp; It's a non-trivial task, but of course once you have a %logscan() macro that will email you, you can use it everywhere.&amp;nbsp; Also, there are plenty of %logscan macros in papers and blog posts etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one I like, and there are more mentioned in the comments:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://bi-notes.com/sas-eg-check-the-log/" target="_blank"&gt;https://bi-notes.com/sas-eg-check-the-log/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other option to scanning the log is to just test &amp;amp;syscc, as you are doing, and when you send an email to notify you of an error, attach the log file to the email.&amp;nbsp; Or sometimes you can put a link to the log file in the body of the email, rather than attach it.&amp;nbsp; Even if you do the log scanning and put the error message in the email, nine times out of 10, you end up opening the full log file.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 14:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638320#M189821</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-04-08T14:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sending emails with program updates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638325#M189823</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a macro written that carries out a procedure n times. I'm printing all from the logs to an external file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following and I'm getting email saying an error has occurred. When I examine the log there is no error?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;DIV class="xis-eDocBody"&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="n02e5p5pl51sxan1gy2dux7qz8b0" class="xis-topicContent"&gt;
&lt;DIV id="p04mnc9m31tnz5n1cixg63v6c91l" class="xis-paragraph"&gt;The warning condition code in SAS sets &lt;FONT style="background-color: #fcdec0;"&gt;&amp;amp;SYSCC&lt;/FONT&gt; to 4. So if you are getting any warnings the macro variable is not 0.&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;Depending on the content of your code you may need to make other changes.
&lt;DIV class="xis-eDocBody"&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="n02e5p5pl51sxan1gy2dux7qz8b0" class="xis-topicContent"&gt;
&lt;DIV id="n0gd95l7cm7qdcn17ab0zzpeyn8h" class="xis-note"&gt;When the ERRORCHECK= SAS system option is set at NORMAL, the value of SYSCC will be 0 even if an error exists in a LIBNAME or FILENAME statement, or in a LOCK statement in &lt;SPAN class="xis-nobr"&gt;SAS/SHARE&lt;/SPAN&gt; software. The value of SYSCC will also be 0 when the %INCLUDE statement fails due to a nonexistent file.&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;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 08 Apr 2020 14:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-emails-with-program-updates/m-p/638325#M189823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T14:24:00Z</dc:date>
    </item>
  </channel>
</rss>

