Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3812
  • Last Modified:

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;
0
Lee R Liddick Jr
Asked:
Lee R Liddick Jr
1 Solution
 
nemws1Database AdministratorCommented:
0
 
theartfuldazzlerCommented:
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
0
 
Lee R Liddick JrReporting AnalystAuthor Commented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Lee R Liddick JrReporting AnalystAuthor Commented:
The case statement doesn't work in this.  I've tried a couple times a couple different ways...including the link you provided.
0
 
Aloysius LowCommented:
does changing  %IF &lob. = 'monkey' %THEN
to  %IF "&lob" = "monkey" %THEN help?
0
 
Lee R Liddick JrReporting AnalystAuthor Commented:
YES...that did it.  Double quotes...really?  Thank you!
0
 
Aloysius LowCommented:
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
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now