DATA Step, Macro, Functions and more

A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 107
Accepted Solution

A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Hello everyone. I need a bit of help in resolving the below error.Please can someone help me out ASAP?

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

      &name EQ R2C

ERROR: The macro MI will stop executing.


%MI(PC,NBS,M&S,MNS,M&S)

(This below code is just a part of a Macro I believe where the error is. You can find the full macro attached.)

Data &Brand;

Set %if &brand ne MNS /*and &brand ne RAC*/ %then NbsMotor.&Set ;

%if &brand eq MNS %then &set ; /*%if &brand eq RAC %then NbsRAC.&set

*/;

Length Channel $ 2;

%if &name EQ R2C %then %do ;

  if Misc_AffinityGroup = 'RA2' ;

Misc_AffinityParent = 'R2C' ;

%end ;

%if &name EQ RAC %then if Misc_AffinityGroup = 'RA1' ;;

  If Misc_Qte_Date = . or Misc_DataQuality ne 'OK' Then delete;

/*  If Quote_ErrorCheck in (1,3) Then delete;*/


Accepted Solutions
Solution
‎02-25-2015 08:03 PM
PROC Star
Posts: 1,231

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Agree with your diagnosis, Kiran.

Would think using %NRSTR() to mask the & should help, e.g.:

%MI(PC,NBS,%NRSTR(M&S),MNS,%NRSTR(M&S))

View solution in original post


All Replies
Super User
Posts: 5,082

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Well, you didn't actually attach the code or give us a clue as to what &NAME contains.  But I would guess adding double quotes would change the functionality of the automatic %EVAL on %if conditions:

%if "&name" EQ "R2C" %then %do;

Good luck.

Frequent Contributor
Posts: 107

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Hi Thank you for your prompt response. Sorry, I could not attach a file as the website did not allow me to. Please find below what the macro contains.Thanks in advance.

%Macro MI(Product,Trntyp,Name,Brand,Brand2);

%MI(PC,NBS,M&S,MNS,M&S)

Super User
Posts: 5,082

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

And did you try the solution I suggested?  It might just be that simple to fix.

Frequent Contributor
Posts: 107

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Hi Astounding,

No, I have not tried yet as I do not have the access to my laptop at the moment. I will let you know once I try. But, I was thinking if the error is due to &name=M&S may be &(and) is taken as &(ampersand) in M&S. Please correct me if I am wrong.

Super User
Posts: 5,082

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Yes, that's probably it.  If you have a macro variable &S, that will give you the wrong result.  But if you don't have such a variable, you'll probably get a combination of a warning plus the correct result.  So try the double quotes and let's see what happens.

Solution
‎02-25-2015 08:03 PM
PROC Star
Posts: 1,231

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Agree with your diagnosis, Kiran.

Would think using %NRSTR() to mask the & should help, e.g.:

%MI(PC,NBS,%NRSTR(M&S),MNS,%NRSTR(M&S))

Frequent Contributor
Posts: 107

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Thank you very much Astounding.That worked.

CAN YOU RECOMMEND ME ANY PERMANENT FIX REMOVING DOLLAR SIGN IN FRONT OF RECORDS. NOT THE (INFORMAT) AS THE TABLES ARE MOVING FROM SQL TO SAS. AND THE VARIABLES SHOULD NOT CHANGE FROM NUMERIC TO CHARACTER.

Frequent Contributor
Posts: 107

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Thanks Quentin and Astounding.

Frequent Contributor
Posts: 107

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Hi Quentin,

I am still stuck with these kind of errors. Tried looking for a fix, thought I would take you guy's advice.

%MI(PC,NBS,%nrstr(M&S),MNS,%nrstr(M&S));

A = Compress("M&S"||'%');

MPRINT(MI): Call Symput('Table_Brand',A);


SYMBOLGEN: Macro variable TABLE_BRAND resolves to M&S%

WARNING: Apparent symbolic reference S not resolved.


What could be the issue?

PROC Star
Posts: 1,231

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

Hi,

I'm not quite able to understand your example.  If you have a step in your macro like:

data _null_;
  a=compress("M&S"||"%");
  call symput("Table_Brand",a);
run;
%put &Table_Brand;

That will throw the warning because M&S looks to SAS like M followed by a reference to a macro variable &S. The & is a macro trigger, telling SAS that a macro variable name is coming.  Macro quoting lets you hide the & from SAS, so it doesn't see a macro trigger.  You could use macro quoting in this case, like:

data _null_;
  a=compress("%nrstr(M&S)"||"%");
  call symput("Table_Brand",a);
run;
%put &Table_Brand;

But it would be unusual to use CALL SYMPUT like that, because you are not reading a data step variable.  So you could achieve the same thing with just a %LET statement, e.g.. :

52   %let Table_Brand=%nrstr(M&A%%);
53   %put &Table_Brand;
M&A%

Hope that helps,

--Q.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 1926 views
  • 5 likes
  • 3 in conversation