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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

2 REPLIES 2
Oligolas
Barite | Level 11

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 -

Tom
Super User Tom
Super User

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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1459 views
  • 1 like
  • 3 in conversation