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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: