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
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.