<?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: How to send an email report even with zero records? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/832971#M329275</link>
    <description>&lt;P&gt;There are several ways to accomplish this but here's one from my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/* after your PROC SQL step, SQLOBS will have the record count */
%let itemcount=&amp;amp;sqlobs.;

%macro emailbody;
  %if &amp;amp;itemcount. &amp;gt; 0 %then %do;
        title "The following items were added in the past 5 days (&amp;amp;SYSDATE.)";       
        proc print data=recent;
        run;
  %end;
  %else %do;
   title;
   ods text="NO recent items added (past 5 days).";
  %end;
%mend;

filename msg email to=&amp;amp;TO_LINE. 
    FROM = "me@email.com"
    subject="Recent entries as of &amp;amp;SYSDATE."
    type='text/html'
    CT ='text/html'
;
ods html(id=email)
  file=msg 
  style=dove;
 %emailbody;
ods html (id=email) close;&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 12 Sep 2022 18:31:06 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2022-09-12T18:31:06Z</dc:date>
    <item>
      <title>How to send an email report even with zero records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/832965#M329272</link>
      <description>&lt;P&gt;I want to send a report to myself every weekday even if the counts are zero..&lt;/P&gt;
&lt;P&gt;My code so far..&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cars_temp as&lt;BR /&gt;select make, origin, count(*) as total&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;group by make, origin;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;options emailsys=smtp emailhost=xxxxxxxxx emailport=25;&lt;/P&gt;
&lt;P&gt;filename temp email&lt;/P&gt;
&lt;P&gt;to = ( 'xxx@xxxxx.xom' )&lt;BR /&gt;from='xxx@xxxxx.xom'&lt;BR /&gt;subject="Daily discrepancies - &amp;amp;rptdt."&lt;BR /&gt;type="text/html"&lt;BR /&gt;ODS html body=temp style = journal;&lt;/P&gt;
&lt;P&gt;TITLE justify= left "Below counts are calculated based on Yesterday's Date ";&lt;BR /&gt;*ods html text = "";&lt;BR /&gt;PROC REPORT DATA=cars_temp nowd HEADLINE HEADSKIP SPLIT='*'&lt;BR /&gt;style (report) = {background = white&lt;BR /&gt;font_face = "Verdana" font_size = 7pt just=left }&lt;BR /&gt;style (column) = {background = white CELLHEIGHT = 2.5%&lt;BR /&gt;font_face = "Verdana" font_size = 7pt just=left}&lt;BR /&gt;style (header) = {foreground = cx5e2750 font_face="Verdana"&lt;BR /&gt;font_size = 8pt just=left&lt;BR /&gt;background = white} ;&lt;/P&gt;
&lt;P&gt;column A B C ;&lt;BR /&gt;define A / group width= 15 "Region * ID";&lt;BR /&gt;define B / group width= 30 "Region * Name"; &lt;BR /&gt;define C / mean width= 30 "Total # * of items ";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;ods html text=" Daily&amp;nbsp; counts";&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ods html text = ".";&lt;/P&gt;
&lt;P&gt;ods _all_ close;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 18:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/832965#M329272</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2022-09-12T18:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email report even with zero records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/832971#M329275</link>
      <description>&lt;P&gt;There are several ways to accomplish this but here's one from my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/* after your PROC SQL step, SQLOBS will have the record count */
%let itemcount=&amp;amp;sqlobs.;

%macro emailbody;
  %if &amp;amp;itemcount. &amp;gt; 0 %then %do;
        title "The following items were added in the past 5 days (&amp;amp;SYSDATE.)";       
        proc print data=recent;
        run;
  %end;
  %else %do;
   title;
   ods text="NO recent items added (past 5 days).";
  %end;
%mend;

filename msg email to=&amp;amp;TO_LINE. 
    FROM = "me@email.com"
    subject="Recent entries as of &amp;amp;SYSDATE."
    type='text/html'
    CT ='text/html'
;
ods html(id=email)
  file=msg 
  style=dove;
 %emailbody;
ods html (id=email) close;&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 12 Sep 2022 18:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/832971#M329275</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2022-09-12T18:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email report even with zero records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/833008#M329296</link>
      <description>Thank you Chris. It worked as desired. &amp;amp;sqlobs is very helpful. Also registered at SAS Explore using the link from your signature line:-)&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Sep 2022 21:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-report-even-with-zero-records/m-p/833008#M329296</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2022-09-12T21:25:25Z</dc:date>
    </item>
  </channel>
</rss>

