Hi, I would like to ask you how to conditionally send an email from sas ?
%let variable1 ='go';
if variable1 = 'go' then do;
FILENAME mail
EMAIL TO=(&emails)
etc ....
end;
Thank you.
You can something like below, consider that the code is within the macro sample, this is an untested code
%macro sample;
%global variable1;
%let variable1=go;
%if &variable1=go %then %do;
filename mail email to='xxxxx@xxxx.com';
data _null_;
file mail;
put 'Hi';
run;
%end;
%mend sample;
%sample
Starting with SAS 9.4M5 (I think), %if can be used in open code (no macro definition necessary):
%let variable1=go;
%if &variable1=go %then %do;
FILENAME mail
EMAIL TO=(&emails)
etc ....
%end;
Note that macro variables very rarely need quotes, quote are usually unnecessary and cause problems.
Is VARIABLE a macro variable, as it it appears in your first statement, or an actual variable in a SAS dataset, as it appears in your second statement? If the later does the data have just one observation? If not what if some of the observations have values of go and other observations have values that are something else? Do you still want to send the email?
Not sure what an elseif is, but there is definitely a macro %ELSE statement.
%if &variable=go %then %do;
....
%end;
%else %if &variable=stop %then %do;
....
%end;
%else %do;
....
%end;
@SIgnificatif wrote:
it's a macro variable
1 I need to use a condition to check the value ,
2 else send another email. ( i found that there is no possibility to do an elseif if in macro variable mode) , limiting this to only 2 conditions...
You can use %else %if, as @Tom already showed, but this needs a macro definition. To implement the same logic in open code, you need to code the else-path with a separate %if:
%if &variable1 = go
%then %do;
%end;
%if &variable1 ne go
%then %do;
%end;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.