BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KiranMaddi
Obsidian | Level 7

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;*/

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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))

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

10 REPLIES 10
Astounding
PROC Star

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.

KiranMaddi
Obsidian | Level 7

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)

Astounding
PROC Star

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

KiranMaddi
Obsidian | Level 7

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.

Astounding
PROC Star

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.

Quentin
Super User

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))

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
KiranMaddi
Obsidian | Level 7

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.

KiranMaddi
Obsidian | Level 7

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?

Quentin
Super User

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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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