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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
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:-)

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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