BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jerathashutosh
Fluorite | Level 6

Hi,

 

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.

 

Currently i make a dataset with the desired data and then i run this code to send an email:

 

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;

 

is there a way i can do something like:

 

if count is not null then (

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;

)

else exit;

 

Thanks.

 

Ashu

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can use macro code to generate SAS code.  With latest version of SAS you can even using simple %IF/%THEN/%DO statements in a regular SAS program.  For older versions (or more complex macro logic) you will need to wrap the code into a macro definition.

 

data _null_;
  call symputx('nobs',nobs);
  stop;
  set work.email nobs=nobs;
run;

%if (&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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

You can use macro code to generate SAS code.  With latest version of SAS you can even using simple %IF/%THEN/%DO statements in a regular SAS program.  For older versions (or more complex macro logic) you will need to wrap the code into a macro definition.

 

data _null_;
  call symputx('nobs',nobs);
  stop;
  set work.email nobs=nobs;
run;

%if (&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;
jerathashutosh
Fluorite | Level 6

works like a charm!

 

Thanks Tom.

 

Ashu

ChrisNZ
Tourmaline | Level 20

Or, if you want to avoid writing macros:

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;

 

 

jerathashutosh
Fluorite | Level 6

this works perfectly as well! 😄

 

Thanks ChrisNZ.

 

Ashu

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1923 views
  • 2 likes
  • 3 in conversation