Search code examples
error-handlingsyntaxsasmacrossas-macro

macro error: A character operand was found in %IF condition


I am getting the "A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &no. = 4" error on the following code:

%MACRO system(no, center);

%if &no. = 4 %then do%;

data system_%no.;
set system1 system2 (rename=(sysid=systemid));
if systemid > (&no. * 4) then delete;
if systemid < ((&no. * 4) -3) then delete;
sysid=systemid+30;
drop systemid;
system = &no.;
center = put(strip("&center."),20.);
run;
%end;

%MEND system;

I can't figure where the issue is coming from


Solution

  • You have a typo in your code do% instead of %do.

    Please show an example of the macro definition and macro call which produces this problem. Here is a simplified version of your macro, it does not produce the error message with these calls:

    %MACRO system(no, center);
    
      %if &no. = 4 %then %do;
        %put I ran &=no;
      %end;
    
    %MEND system;
    
    %system(,foo)
    %system(3,foo)
    %system(4,foo)
    %system(5,foo)
    

    It would be possible to produce the error message with a call like:

    %system(OR,foo)
    

    In that case you could use macro quoting to avoid the problem, but I doubt that is happening in your case, from what you describe.

    When testing the macro, do not just highlight and submit part of the macro definition. You need to submit the entire macro definition in order to compile it, and then submit a macro call to invoke it.

    Be sure to review your entire log, from both the step that compiles the macro and the macro execution, to make sure there are no error messages.