Good Day!
I am trying to call an email macro from an IF based on a stored value. I am sending to different individuals based on the setting of flag.
data _null_ ;
if flag = 'T" then ;
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
else ;
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;
Since the data step variable FLAG never equals "T", you will always execute the ELSE clause, but you have syntax errors and incorrect semi-colons.
data _null_ ;
if flag = "T" then
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
else
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;
but I think you might really want a SET statement so FLAG has a value that might be "T"
data _null_ ;
set somedataset;
if flag = "T" then
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
else
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;
And then whatever %genmail does can only contain DATA step code, if there's a PROC in there, the whole thing fails.
But, there are lots of problems here. Whether FLAG="T" or not, you execute the same macro with the same arguments. Why?
Perhaps you ought to start over and explain what you are trying to do, rather than putting up such problematic code and have us guess what you are trying to do.
Since the data step variable FLAG never equals "T", you will always execute the ELSE clause, but you have syntax errors and incorrect semi-colons.
data _null_ ;
if flag = "T" then
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
else
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;
but I think you might really want a SET statement so FLAG has a value that might be "T"
data _null_ ;
set somedataset;
if flag = "T" then
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
else
%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;
And then whatever %genmail does can only contain DATA step code, if there's a PROC in there, the whole thing fails.
But, there are lots of problems here. Whether FLAG="T" or not, you execute the same macro with the same arguments. Why?
Perhaps you ought to start over and explain what you are trying to do, rather than putting up such problematic code and have us guess what you are trying to do.
Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &flag = 'T'..........
@JeffreyLowe wrote:
Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &flag = 'T'..........
This syntax works only if the value of &FLAG is a character string with quotes around it ... in which case, why even bother with DATA _NULL_;? Do it all with macro %IF and not within a DATA step.
%if &flag=T %then ... ; /* Note, you don't put macro variable values in quotes */
@PaigeMiller wrote:
@JeffreyLowe wrote:
Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &flag = 'T'..........
This syntax works only if the value of &FLAG is a character string with quotes around it ... in which case, why even bother with DATA _NULL_;? Do it all with macro %IF and not within a DATA step.
%if &flag=T %then ... ; /* Note, you don't put macro variable values in quotes */
Adding to the above ... if you really want to test &flag='T', this is a situation where double quotes and single quotes cannot be mixed and matched. If, for example, the value of &flag is "T", you will not get a match. Only if &flag is 'T' will you get a match, and this doesn't seem like a good way to do the comparison (which is one reason why I say macro variable values should not be enclosed in quotes).
Thank you Paige!
Adding:
Yes, I agree with @Reeza , that CALL EXECUTE would be a better method of executing this macro if it doesn't contain valid DATA step code.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.