This is a very silly beginner question but would like to seek some advise. I'm getting this error when the value of the macro variable layer has a dash. Seems like it's still trying to evaluate it even I have placed %str.
This is the error I get and the code sample below.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is
required. The condition was: &layer = stg or &layer = stg-m
options symbolgen;
%let layer=stg-m;
%macro test;
%if %str(&layer) = %str(stg) or %str(&layer) = %str(stg-m) %then %do;
%put CORRECT;
%end;
%mend;
%test;
@milts wrote:
This is a very silly beginner question but would like to seek some advise. I'm getting this error when the value of the macro variable layer has a dash. Seems like it's still trying to evaluate it even I have placed %str.
This is the error I get and the code sample below.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is
required. The condition was: &layer = stg or &layer = stg-m
options symbolgen; %let layer=stg-m; %macro test; %if %str(&layer) = %str(stg) or %str(&layer) = %str(stg-m) %then %do; %put CORRECT; %end; %mend; %test;
You need to use %quote around &layer, and you don't need to include stg in the %str() function
%if %quote(&layer) = stg or %quote(&layer) = %str(stg-m) %then %do;
A simple solution is to add double quotes around everything:
%if "&layer" = "stg" or "&layer" = "stg-m" %then %do;
The double quotes suppress macro language's urge to treat the dash as an instruction to subtract.
For this to work, you have to be careful to construct &LAYER with no leading or trailing blanks.
Yeah. minus is a special character for macro facility, you need mask it.
Since it is in a macro variable ,use %bquote() better. %str() is for string .
options symbolgen;
%let layer=stg-m;
%macro test;
%if %bquote(&layer) = %str(stg) or %bquote(&layer) = %str(stg-m) %then %do;
%put CORRECT;
%end;
%mend;
%test
options symbolgen;
%let layer=stg-m;
%macro test/minoperator mindelimiter=' ';
%if %bquote(&layer) in %str(stg) %str(stg-m) %then %do;
%put CORRECT;
%end;
%mend;
%test
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.