@Rick_SAS provided a great explanation about global statements versus those that are scoped to your DATA step. Here's an example that shows how to conditionally send an e-mail based on the values that you find in your data. This approach uses the %IF-%THEN-%ELSE statements in open code, which has been possible since SAS 9.4 Maint 5 (released in 2017).
/* Pretend we are counting records where RESULT=1 */
proc sql noprint;
select count(result) into: mkt_count
from source.dataset
where result=1;
quit;
/* If beyond a certain threshold, send e-mail */
options nocenter emailhost='yourmailhost.company.com' emailsys=smtp;
%if &mkt_count. > 350 %then
%do;
filename msg email to=(
'analyst@xyz.com'
)
FROM = "admin@xyz.com"
subject="Alert: Count = &mkt_count., exceeds target"
type='text/html'
;
ods msoffice2k (id=email)
file=msg (title="Alert")
style=dove;
ods noproctitle;
/* SAS proc to generate the body of the e-mail */
title "Results distribution";
proc freq data=source.dataset;
table result;
run;
ods msoffice2k (id=email) close;
%end;
/* under threshold, no alert needed */
%else %do;
%PUT NOTE: Count is &mkt_count. -- under threshold;
%end;
... View more