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;*/
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))
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.
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)
And did you try the solution I suggested? It might just be that simple to fix.
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.
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.
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))
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.
Thanks Quentin and Astounding.
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?
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.