<?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 Sending Email and attachment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863454#M341074</link>
    <description>&lt;P&gt;Hello, hope everyone is alright.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to ask if someone has a ready code on how to stop sending an email with attachment when there's error in the data steps, instead send an 'error' email to myself.&lt;/P&gt;
&lt;P&gt;I have written the below code but it's not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;syscc=0 %then %do;&lt;BR /&gt;proc export data=Test_List&lt;BR /&gt;dbms=xlsx&lt;BR /&gt;replace&lt;BR /&gt;outfile='\\SAS_WIP\Test_List';&lt;BR /&gt;sheet='Sheet1';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;filename mymail email 'myemail@email.com'&lt;BR /&gt;from='myemail &amp;lt;myemail@email.com&amp;gt;'&lt;BR /&gt;subject='Test List'&lt;BR /&gt;attach=("\\SAS_WIP\Test_List.xlsx");&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;file mymail&lt;BR /&gt;to=('yourmail@email.com'&lt;BR /&gt;)&lt;BR /&gt;cc=('myemail@email.com');&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;BR /&gt;filename mymail email 'myemail@email.com'&lt;BR /&gt;from='InternalReports &amp;lt;myemail@email.com&amp;gt;'&lt;BR /&gt;subject='Test List';&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;file mymail&lt;BR /&gt;to=('myemail@email.com');&lt;BR /&gt;put "ERROR :(";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 14:41:43 GMT</pubDate>
    <dc:creator>Eugenio211</dc:creator>
    <dc:date>2023-03-10T14:41:43Z</dc:date>
    <item>
      <title>Sending Email and attachment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863454#M341074</link>
      <description>&lt;P&gt;Hello, hope everyone is alright.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to ask if someone has a ready code on how to stop sending an email with attachment when there's error in the data steps, instead send an 'error' email to myself.&lt;/P&gt;
&lt;P&gt;I have written the below code but it's not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;syscc=0 %then %do;&lt;BR /&gt;proc export data=Test_List&lt;BR /&gt;dbms=xlsx&lt;BR /&gt;replace&lt;BR /&gt;outfile='\\SAS_WIP\Test_List';&lt;BR /&gt;sheet='Sheet1';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;filename mymail email 'myemail@email.com'&lt;BR /&gt;from='myemail &amp;lt;myemail@email.com&amp;gt;'&lt;BR /&gt;subject='Test List'&lt;BR /&gt;attach=("\\SAS_WIP\Test_List.xlsx");&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;file mymail&lt;BR /&gt;to=('yourmail@email.com'&lt;BR /&gt;)&lt;BR /&gt;cc=('myemail@email.com');&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;BR /&gt;filename mymail email 'myemail@email.com'&lt;BR /&gt;from='InternalReports &amp;lt;myemail@email.com&amp;gt;'&lt;BR /&gt;subject='Test List';&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;file mymail&lt;BR /&gt;to=('myemail@email.com');&lt;BR /&gt;put "ERROR :(";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863454#M341074</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-03-10T14:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Email and attachment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863456#M341076</link>
      <description>&lt;P&gt;Can you say more about what you mean by "not working"?&amp;nbsp; Is the macro sending the wrong email (if so, it could be that &amp;amp;syscc is not being set).&amp;nbsp; Or is your macro generating an error?&amp;nbsp; When you have an error in your main code, does SAS enter syntaxcheckmode (set obs=0)?&amp;nbsp; If so, than you may need to recover from syntaxcheckmode with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(getoption(obs))=0 %then %do;
  options obs=max replace NoSyntaxCheck;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so that your data _null_ step will execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 14:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863456#M341076</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-10T14:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Email and attachment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863462#M341079</link>
      <description>it's sending the error message even though there's no error in the data steps.</description>
      <pubDate>Fri, 10 Mar 2023 15:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863462#M341079</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-03-10T15:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Email and attachment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863463#M341080</link>
      <description>&lt;P&gt;Add %put &amp;amp;=syscc; before the code, to see what the value of SYSCC is.&amp;nbsp; Or turn on options SYMBOLGEN MLOGIC.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure you are using a new clean session when you test the code.&amp;nbsp; Some tools like DI studio will maintain a session across multiple submissions.&amp;nbsp; As a hack, you can %let syscc=0; at the top of your program to force it to start at 0.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 15:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sending-Email-and-attachment/m-p/863463#M341080</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-10T15:16:57Z</dc:date>
    </item>
  </channel>
</rss>

