<?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 from SAS only if data exists? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554756#M154359</link>
    <description>&lt;P&gt;You can use macro code to generate SAS code.&amp;nbsp; With latest version of SAS you can even using simple %IF/%THEN/%DO statements in a regular SAS program.&amp;nbsp; For older versions (or more complex macro logic) you will need to wrap the code into a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('nobs',nobs);
  stop;
  set work.email nobs=nobs;
run;

%if (&amp;amp;nobs) %then %do;

filename outbox email
  to=("abc@gmail.com")
  type='text/html'
  subject="Today's Details"
  from='abc@gmail.com'
;
ods html body=outbox;
proc print data= WORK.EMAIL;
run;
ods html close;

%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Apr 2019 16:00:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-04-29T16:00:05Z</dc:date>
    <item>
      <title>How to send an email from SAS only if data exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554751#M154356</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a daily email that goes out, but i want to send the email only when data exists. Currently it sends an email no matter if the data exists or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently i make a dataset with the desired data and then i run this code to send an email:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;filename outbox email&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;to=("abc@gmail.com")&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;type='text/html'&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;subject="Today's Details"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from='abc@gmail.com';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ods html body=outbox;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;proc print data= WORK.EMAIL;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ods html close;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a way i can do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if count is not null then (&lt;/P&gt;&lt;P&gt;&lt;EM&gt;filename outbox email&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;to=("abc@gmail.com")&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;type='text/html'&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;subject="Today's Details"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from='abc@gmail.com';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ods html body=outbox;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;proc print data= WORK.EMAIL;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ods html close;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;else exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ashu&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 15:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554751#M154356</guid>
      <dc:creator>jerathashutosh</dc:creator>
      <dc:date>2019-04-29T15:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from SAS only if data exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554756#M154359</link>
      <description>&lt;P&gt;You can use macro code to generate SAS code.&amp;nbsp; With latest version of SAS you can even using simple %IF/%THEN/%DO statements in a regular SAS program.&amp;nbsp; For older versions (or more complex macro logic) you will need to wrap the code into a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('nobs',nobs);
  stop;
  set work.email nobs=nobs;
run;

%if (&amp;amp;nobs) %then %do;

filename outbox email
  to=("abc@gmail.com")
  type='text/html'
  subject="Today's Details"
  from='abc@gmail.com'
;
ods html body=outbox;
proc print data= WORK.EMAIL;
run;
ods html close;

%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Apr 2019 16:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554756#M154359</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-29T16:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from SAS only if data exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554901#M154410</link>
      <description>&lt;P&gt;works like a charm!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ashu&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 02:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554901#M154410</guid>
      <dc:creator>jerathashutosh</dc:creator>
      <dc:date>2019-04-30T02:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from SAS only if data exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554913#M154417</link>
      <description>&lt;P&gt;Or, if you want to avoid writing macros:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if NOBS then call execute(catt(
     "filename OUTBOX email            "
   , " to=('abc@gmail.com')            "
   , " type='text/html'                "
   , " subject=""Today's Details""     "
   , " from='abc@gmail.com' ;          "
   , "ods html body=OUTBOX;            "
   , "proc print data=WORK.EMAIL; run; "
   , "ods html close;                  " 
   , "filename OUTBOX clear;           " ));
  stop;
  set WORK.EMAIL nobs=NOBS;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 03:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/554913#M154417</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-30T03:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from SAS only if data exists?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/555753#M154692</link>
      <description>&lt;P&gt;this works perfectly as well! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks ChrisNZ.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ashu&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 20:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-SAS-only-if-data-exists/m-p/555753#M154692</guid>
      <dc:creator>jerathashutosh</dc:creator>
      <dc:date>2019-05-02T20:21:44Z</dc:date>
    </item>
  </channel>
</rss>

