Hi.
I don't use a macro in SAS very often. There is one that I use to send e-mails. However, I don't want this macro to be used every time. I want to add a condition that if the WORK.TEST table is empty (no rows) then do not execute the macro, otherwise it will execute the macro.
Macro code is here:
%macro send_email(to, subject);
FILENAME Mailbox EMAIL;
data _NULL_;
file MailBox
to=(&to.)
from='noreply@***.com'
subject=&subject.;
put "This is email sent by macro.";
run;
%mend;
%let today_d = %sysfunc(date(), DDMMYY10.);
%let emails_to = "myemail@***.com";
%let subject = "Subject of mail and date: &today_d.";
%send_email(&emails_to., &subject.);
Can You help me with solution how to execute macro if work.test is not empty?
Here you go:
data _NULL_;
if 0 then set WORK.TEST nobs=n;
put "no. of observations =" n;
if n^=0 then call execute("%nrstr(%send_email(&emails_to., &subject.);)");
stop;
run;
- Cheers -
Here you go:
data _NULL_;
if 0 then set WORK.TEST nobs=n;
put "no. of observations =" n;
if n^=0 then call execute("%nrstr(%send_email(&emails_to., &subject.);)");
stop;
run;
- Cheers -
You can take advantage of the fact that SAS will end a data step when you read past the end of the data to simplify that step.
data _NULL_;
put "no. of observations =" n;
set WORK.TEST nobs=n;
call execute("%nrstr(%send_email(&emails_to., &subject.);)");
stop;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.