DATA Step, Macro, Functions and more

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand

Reply
Contributor
Posts: 40

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand

Hi

 

I am getting below error when executing below stmnt in a macro . Val is numeric and runstatus is character .

 

%if (val=0) AND (Runstatus = 'F' or RUNSTATUS='' ) %then 

 

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
val=1 and runstatus = "F" or ""

 

Kindly advise.Thanks

Super User
Posts: 10,623

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

The text(!) val is never numeric; either you missed using the ampersand for macro variable &val, or you tried to access a data step variable, which is impossible from the macro preprocessor.

To clarify, post your complete code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,866

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

%if construct is a macro function.  You cannot use datastep variables in the construct - macro is resolved before datastep compilation.

 

Post your code on what you are trying to do - we can't tell from tiny snippets.  First question would be why you are using a macro if construct to try to check datastep variables which will not work.

Contributor
Posts: 40

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Hi. Yes am tryinh to access a datastep variable.

Data _null_
Set work.abc
if (val=0) AND (Runstatus = 'F' or RUNSTATUS='' ) %then



Both val and runstatus in abc table. Am doin in a loop inside a macro. Please advise how to reference both these varible in a macro. Thanks
Super User
Posts: 10,623

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

You CANNOT access data step variables from macro code, period. Use data step code instead.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 40

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Hi. Thanks. I wil try normal if else inside a data step . Is it possible to create a data step inside a datastel and uae filename statement?
Super User
Posts: 10,623

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

There can only be one datastep active at any given time. Please describe what you want to accomplish, post example data (in a data step to easily recreate your data), and what your expected result should look like.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,866

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Post examples, show test data in the form of a datastep, and what you want to achieve.  Its hard to keep guessing what you mean.  You can create code from one datastep in numerous ways:

data _null_;
  set have;
  if val=1 then call execute('data want;  file "abc.txt";...;run;');
run;

For example.

Contributor
Posts: 40

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Hi. I want to try similar to wat you have posted. I will try and update here. Thanks for your reply.
Ask a Question
Discussion stats
  • 8 replies
  • 162 views
  • 0 likes
  • 3 in conversation