gdogg371
gdogg371

Reputation: 4122

Parameterised SQL WHERE statement and SAS Macro Language problems

I have a piece of code that has parameterised a hundred or so similar, but not identical SQL statements I need to generate data I require. The parameterisation works fine apart from the where statements. I am passing in a macro string of the following format:

where PERIOD_LAST_DTTM = '31DEC2017:23:59:59'dt
  and myvar1 = 1 and myvar2 < 0
  and myvar3 in ('SOME STRING', 'SOME OTHER STRING')  

...with the following syntax:

%if %eval(&inn_sel_var. ^= &comp_var2.) %then %do;

        &inn_sel_var.

%end;   

/&inn_sel_var is where string &comp_var2 = NULL/

...but am getting the following error:

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       where PERIOD_LAST_DTTM = '31DEC2017:23:59:59'dt and myvar1 = 1 and myvar2 < 0 and myvar3 in ('SOME STRING', 'SOME OTHER STRING')                                                                                    


             ^= NULL 
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
ERROR: The macro MODEL_CHECKS will stop executing.

...I have tried using %STR, %SUPERQ, %QUOTE, %BQUOTE, %NRQUOTE, %NRBQUOTE and %UNQUOTE, but I keep on hitting errors. Could someone please advise what I need to do in order for feed my parameterised where statements in correctly?

Thanks

Upvotes: 0

Views: 75

Answers (1)

Tom
Tom

Reputation: 51566

You need to show more of your program and/or log.

But using %superq() should prevent that type of error message in your %IF statement.

%if %superq(inn_sel_var) ne %superq(comp_var2) %then &inn_sel_var. ;

Of course the value of the INN_SEL_VAR macro variable might still generate errors in the generated SAS code.

Upvotes: 1

Related Questions