Lee R Liddick Jr
asked on
IF/THEN in PROC SQL statement of SAS
Having problems with an IF/THEN statement in a PROC SQL; statement of SAS. What am I missing or doing wrong? Not even getting any errors...just not doing what it should:
proc sql;
create table NEW_TBL as
select distinct
FIELD1, FIELD2, FIELD3, FIELD4, FIELD5,
%IF &lob. = 'monkey' %THEN
%DO;
FIELD100,
%END;
FIELD6, FIELD7
from OLD_TBL;
quit;
proc sql;
create table NEW_TBL as
select distinct
FIELD1, FIELD2, FIELD3, FIELD4, FIELD5,
%IF &lob. = 'monkey' %THEN
%DO;
FIELD100,
%END;
FIELD6, FIELD7
from OLD_TBL;
quit;
Hi
You are using macro %If's - so I assume you are running this in a Macro.
The best way to check what the output of a Macro is - is to use:
Then set the macro variable to 'monkey', and see what pops out in the log
You are using macro %If's - so I assume you are running this in a Macro.
The best way to check what the output of a Macro is - is to use:
OPTION MPRINT;
Then set the macro variable to 'monkey', and see what pops out in the log
ASKER
This is in a macro...not sure where to put this mprint. I'm tried a few things and nothing really is showing in the log.
ASKER
The case statement doesn't work in this. I've tried a couple times a couple different ways...including the link you provided.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YES...that did it. Double quotes...really? Thank you!
actually, because the value passed in was just monkey, thus to do a string comparison, you need to add quotation marks... however, when doing macros, single quotation marks results in the variable being un-parsed i.e. treated as literal value ('&lob' really means &lob instead of monkey), so you'll need to use double quotes to enclose both the variable ("&lob") and the string value ("monkey") :)
your original code would have worked if you had passed in 'monkey' instead of monkey into the macro
your original code would have worked if you had passed in 'monkey' instead of monkey into the macro
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473682.htm