<?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 Send email if scheduled SAS job errors in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Send-email-if-scheduled-SAS-job-errors/m-p/567923#M159767</link>
    <description>&lt;P&gt;I have a SAS job that is scheduled to run once a month.&amp;nbsp; For the past several months it has thrown the following error(s):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: CLI error trying to establish connection: FATAL 1: database connection refused&lt;/P&gt;&lt;P&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because the server changed without my knowledge.&amp;nbsp; I would like to have these errors sent to me if possible.&amp;nbsp; I tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;send_mail&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;filename mymail email &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'dsmith2@somewhere.com'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; subject=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'ERROR in job'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;syscc&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;syscc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file mymail;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'An ERROR has occurred in the SAS datasets code'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;file mymail;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'The SAS datasets job ran to completion'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;%mend&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;send_mail&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put it right after the libname statement.&amp;nbsp; It sends an email but the message is "The SAS datasets job ran to completion."&amp;nbsp; I understand I might have to have the program run, save the log, and parse it for the error and then run the program again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How does this work with a scheduled job?&amp;nbsp; Do I need to put it on the scheduler twice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Debbie&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jun 2019 14:21:57 GMT</pubDate>
    <dc:creator>dcooper210</dc:creator>
    <dc:date>2019-06-21T14:21:57Z</dc:date>
    <item>
      <title>Send email if scheduled SAS job errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Send-email-if-scheduled-SAS-job-errors/m-p/567923#M159767</link>
      <description>&lt;P&gt;I have a SAS job that is scheduled to run once a month.&amp;nbsp; For the past several months it has thrown the following error(s):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: CLI error trying to establish connection: FATAL 1: database connection refused&lt;/P&gt;&lt;P&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because the server changed without my knowledge.&amp;nbsp; I would like to have these errors sent to me if possible.&amp;nbsp; I tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;send_mail&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;filename mymail email &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'dsmith2@somewhere.com'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; subject=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'ERROR in job'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;syscc&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;syscc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file mymail;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'An ERROR has occurred in the SAS datasets code'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;file mymail;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'The SAS datasets job ran to completion'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;%mend&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;send_mail&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put it right after the libname statement.&amp;nbsp; It sends an email but the message is "The SAS datasets job ran to completion."&amp;nbsp; I understand I might have to have the program run, save the log, and parse it for the error and then run the program again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How does this work with a scheduled job?&amp;nbsp; Do I need to put it on the scheduler twice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Debbie&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 14:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Send-email-if-scheduled-SAS-job-errors/m-p/567923#M159767</guid>
      <dc:creator>dcooper210</dc:creator>
      <dc:date>2019-06-21T14:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Send email if scheduled SAS job errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Send-email-if-scheduled-SAS-job-errors/m-p/568096#M159855</link>
      <description>&lt;P&gt;What scheduler are you using? Some schedulers will automatically email you if there is an error. We use this functionality with the LSF scheduler and it means you don't have to code anything.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2019 00:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Send-email-if-scheduled-SAS-job-errors/m-p/568096#M159855</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-06-22T00:51:02Z</dc:date>
    </item>
  </channel>
</rss>

