BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Stalk
Pyrite | Level 9

I want to send a report to myself every weekday even if the counts are zero..

My code so far..


proc sql;
create table cars_temp as
select make, origin, count(*) as total
from sashelp.cars
group by make, origin;
quit;

options emailsys=smtp emailhost=xxxxxxxxx emailport=25;

filename temp email

to = ( 'xxx@xxxxx.xom' )
from='xxx@xxxxx.xom'
subject="Daily discrepancies - &rptdt."
type="text/html"
ODS html body=temp style = journal;

TITLE justify= left "Below counts are calculated based on Yesterday's Date ";
*ods html text = "";
PROC REPORT DATA=cars_temp nowd HEADLINE HEADSKIP SPLIT='*'
style (report) = {background = white
font_face = "Verdana" font_size = 7pt just=left }
style (column) = {background = white CELLHEIGHT = 2.5%
font_face = "Verdana" font_size = 7pt just=left}
style (header) = {foreground = cx5e2750 font_face="Verdana"
font_size = 8pt just=left
background = white} ;

column A B C ;
define A / group width= 15 "Region * ID";
define B / group width= 30 "Region * Name";
define C / mean width= 30 "Total # * of items ";
run;

ods html text=" Daily  counts";


ods html text = ".";

ods _all_ close;

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

There are several ways to accomplish this but here's one from my code.

 

/* after your PROC SQL step, SQLOBS will have the record count */
%let itemcount=&sqlobs.;

%macro emailbody;
  %if &itemcount. > 0 %then %do;
        title "The following items were added in the past 5 days (&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=&TO_LINE. 
    FROM = "me@email.com"
    subject="Recent entries as of &SYSDATE."
    type='text/html'
    CT ='text/html'
;
ods html(id=email)
  file=msg 
  style=dove;
 %emailbody;
ods html (id=email) close;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

2 REPLIES 2
ChrisHemedinger
Community Manager

There are several ways to accomplish this but here's one from my code.

 

/* after your PROC SQL step, SQLOBS will have the record count */
%let itemcount=&sqlobs.;

%macro emailbody;
  %if &itemcount. > 0 %then %do;
        title "The following items were added in the past 5 days (&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=&TO_LINE. 
    FROM = "me@email.com"
    subject="Recent entries as of &SYSDATE."
    type='text/html'
    CT ='text/html'
;
ods html(id=email)
  file=msg 
  style=dove;
 %emailbody;
ods html (id=email) close;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Stalk
Pyrite | Level 9
Thank you Chris. It worked as desired. &sqlobs is very helpful. Also registered at SAS Explore using the link from your signature line:-)
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 946 views
  • 3 likes
  • 2 in conversation