<?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 Only When Data Exists in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216918#M14195</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use SAS Macro code to decide if I should send an email.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, set up a macro variable to check if your dataset has any observations in it.&amp;nbsp; (I am sure there are other ways to determine the number of observations in a dataset, so I'd like to hear input on that.)&lt;/P&gt;&lt;P&gt;%LET HaveData = 0 ;&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET &amp;lt;yourdataset&amp;gt; nobs=NumObs ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CALL SYMPUT("HaveData", LEFT(NumObs)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;%PUT HaveData = &amp;amp;HaveData ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, embed your email steps in a macro, so you can dynamically execute the code, if HaveData &amp;gt; 0, like:&lt;/P&gt;&lt;P&gt;%MACRO SendEmail ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %IF &amp;amp;HaveData &amp;gt; 0 %THEN %DO ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; email code here...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END ;&lt;/P&gt;&lt;P&gt;%MEND SendEmail ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Execute the macro ;&lt;/P&gt;&lt;P&gt;%SendEmail&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Jul 2015 13:31:08 GMT</pubDate>
    <dc:creator>cwilson</dc:creator>
    <dc:date>2015-07-02T13:31:08Z</dc:date>
    <item>
      <title>Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216917#M14194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have some code that sends an email from a proc print statement that works.&amp;nbsp; However, even if no data exists, the email is still being sent.&amp;nbsp; Is there a way to control this when sending using the proc print?&amp;nbsp; I'm sure there's a better/easier way to do this, but this is what I have now:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename outfile email&lt;/P&gt;&lt;P&gt;to = (&amp;lt;emails&amp;gt;)&lt;/P&gt;&lt;P&gt;TYPE = 'TEXT/HTML'&lt;/P&gt;&lt;P&gt;subject = &amp;lt;re&amp;gt;&lt;/P&gt;&lt;P&gt;from = &amp;lt;from&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods listing close;&lt;/P&gt;&lt;P&gt;ODS HTML Body = outfile style = sasweb;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;title BOLD HEIGHT=4 &amp;lt;title&amp;gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=&amp;lt;data&amp;gt; split='/' noobs;&lt;/P&gt;&lt;P&gt;&amp;nbsp; *PRINT FUNCTIONALITY HERE&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;title;&lt;/P&gt;&lt;P&gt;ods html close;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 14:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216917#M14194</guid>
      <dc:creator>akordula</dc:creator>
      <dc:date>2015-06-30T14:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216918#M14195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use SAS Macro code to decide if I should send an email.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, set up a macro variable to check if your dataset has any observations in it.&amp;nbsp; (I am sure there are other ways to determine the number of observations in a dataset, so I'd like to hear input on that.)&lt;/P&gt;&lt;P&gt;%LET HaveData = 0 ;&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET &amp;lt;yourdataset&amp;gt; nobs=NumObs ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CALL SYMPUT("HaveData", LEFT(NumObs)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;%PUT HaveData = &amp;amp;HaveData ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, embed your email steps in a macro, so you can dynamically execute the code, if HaveData &amp;gt; 0, like:&lt;/P&gt;&lt;P&gt;%MACRO SendEmail ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %IF &amp;amp;HaveData &amp;gt; 0 %THEN %DO ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; email code here...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END ;&lt;/P&gt;&lt;P&gt;%MEND SendEmail ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Execute the macro ;&lt;/P&gt;&lt;P&gt;%SendEmail&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 13:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216918#M14195</guid>
      <dc:creator>cwilson</dc:creator>
      <dc:date>2015-07-02T13:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216919#M14196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I completely understand where you're going with that and I think it would work perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem is that my data set ALWAYS has observations in it and i'm putting a where condition in my proc print to only display the records that I want.&amp;nbsp; I was curious if there was a way to send/not send emails using that method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do it this way because I frequently change my where clause to get different variations of the data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 13:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216919#M14196</guid>
      <dc:creator>akordula</dc:creator>
      <dc:date>2015-07-02T13:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216920#M14197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I guess the simplest solution would be to add a data step to create a subset with your where clause, and then use THAT in your data _null_ step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%LET HaveData = 0 ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data yoursubset ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data yourdataset(where=(whereclause)) ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_ ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; SET &amp;lt;yoursubset&amp;gt; nobs=NumObs ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; CALL SYMPUT("HaveData", LEFT(NumObs)) ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; stop ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%PUT HaveData = &amp;amp;HaveData ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 14:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216920#M14197</guid>
      <dc:creator>cwilson</dc:creator>
      <dc:date>2015-07-02T14:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216921#M14198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, just thought of another way to get the count, especially if you have a really large dataset, and you don't want to create a new subset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*) into: HaveData&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;lt;yourdataset&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where whereclause ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 14:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216921#M14198</guid>
      <dc:creator>cwilson</dc:creator>
      <dc:date>2015-07-02T14:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216922#M14199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Akordula,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check the below code and see if it works for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x = 1; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x = 2; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x = 3; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x = 3; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro sendmail;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select count(*) into :n from mydata where x = 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put &amp;amp;n;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;n gt 0 %then&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put your email code here;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Value are no values to print/mail;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%sendmail&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 14:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216922#M14199</guid>
      <dc:creator>AmitRathore</dc:creator>
      <dc:date>2015-07-02T14:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Send Email Only When Data Exists</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216923#M14200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This worked perfectly.&amp;nbsp; Thanks!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 14:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Send-Email-Only-When-Data-Exists/m-p/216923#M14200</guid>
      <dc:creator>akordula</dc:creator>
      <dc:date>2015-07-02T14:41:38Z</dc:date>
    </item>
  </channel>
</rss>

