Link to home
Start Free TrialLog in
Avatar of Lee R Liddick Jr
Lee R Liddick JrFlag for United States of America

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;
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

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:

OPTION MPRINT;

Open in new window


Then set the macro variable to 'monkey', and see what pops out in the log
Avatar of Lee R Liddick Jr

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.
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
Avatar of Aloysius Low
Aloysius Low
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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