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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1028 views
  • 1 like
  • 3 in conversation