BookmarkSubscribeRSS Feed
sofisaas
Calcite | Level 5

Hi everyone,

I have an issue with a macro-variable. I have set up a macro in which I collect values of two macro variable (call symput). But when I try to write a condition on the value of one of these macro variable, I have an error message which tells me :

ERROR: A character operand was found IN the %EVAL FUNCTION OR %IF condition WHERE a numeric

operand IS required. The condition was: &&PARCOURS_&j.="IND"

ERROR: The macro TAPIS will stop executing

Here is my macro:

%macro tapis;

data _null_; set tapis;

  CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);

run;

data _null_; set tapis;

  CALL SYMPUT("Total",_n_);

run;

data tapis2; set tapis;

  %do j=1 %to &TOTAL.;

  %put PARCOURS_&j. : &&PARCOURS_&j.;

  %if &&PARCOURS_&j.="IND" %then %do;

  %put toto;

  %end;

       %end;

run;

%mend;

          %tapis;

Can you help me? Thank you in advance

5 REPLIES 5
sofisaas
Calcite | Level 5

Oh, my code doesn't appear clearly. Here it is again:

%macro tapis;

data _null_; set tapis;

  CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);

run;

data _null_; set tapis;

  CALL SYMPUT("Total",_n_);

run;

data tapis2; set tapis;

  %do j=1 %to &TOTAL.;

  %put PARCOURS_&j. : &&PARCOURS_&j.;

  %if &&PARCOURS_&j.="IND" %then %do;

  %put toto;

  %end;

  %end;

run;

%mend;

%tapis;

Amir
PROC Star

Hi,

Well done on posting your code and the error message; a sample of data can also be helpful.

To try and address the error message you are getting can you post what the log shows for:

%put PARCOURS_&j. : &&PARCOURS_&j.;

just before the error happens.

I think it would be helpful for you to use obtain more information about the macro code when it is running by submitting the following:

options mprint symbolgen mlogic;

before you run your code, as it will provide more information in the log which could be helpful if posted here.

There are some other points of note about your code such as the macro do loop *not* needing to be in a data step, and the quotes around "IND" possibly not being necessary, but I doubt they will be causing the error you've reported.

For now, please supply what the %put statement shows at the time of the error and / or the log when you use the options statement as that would be provide more information. Some sample data might also be useful.

Regards,

Amir.

Quentin
Super User

Hi,

%IF statement will throw that error if you end up with a value like AND or OR which it thinks as an operator, rather than just a text value.

I added a data generation step below.  Your original code works until I add pjc="And".

To fix it, I added macro quoting (see %BQUOTE on %IF statement), which will mask the meaning of AND, OR, etc, so that they are treated as a text string.

HTH,

--Q.

%macro tapis;

%*Value AND below causes %eval to error from %IF statement ;
%*Unless use macro quoting;
data tapis;
  pjc="AAA"; output;
  pjc="IND"; output;
  pjc="And"; output; 
run;


data _null_; set tapis;
  CALL SYMPUT(COMPRESS("PARCOURS_"||_N_),PJC);
run;

 
 
data _null_; set tapis;
  CALL SYMPUT("Total",_n_);
run;

 
data tapis2; set tapis;
  %do j=1 %to &TOTAL.;
    %put PARCOURS_&j. : &&PARCOURS_&j.;

    /*%if &&PARCOURS_&j.="IND" %then %do;*/
    %if %bquote(&&PARCOURS_&j.)=IND %then %do;
      %put toto;
    %end;
  %end;
run;

%mend;

%tapis
The Boston Area SAS Users Group is hosting free webinars!
Next up: Lisa Mendez & Richann Watson present Get Tipsy with Debugging Tips for SAS® Code: The After Party on Wednesday Jul 16.
Register now at https://www.basug.org/events.
Astounding
PROC Star

Quentin has hit on the right issue.  But there is more than one possible approach.

Note that your macro variable contains the three characters IND.  It does not contain the five characters "IND".  So Quentin is right to remove the quotes when applying %BQUOTE.  However, you could also go the opposite route to make your program work.

First, switch to CALL SYMPUTX to automatically remove leading or trailing blanks:

call symputx(..., PJC);

Then use double quotes on both sides of the comparison:

%if "&&PARCOURS_&j."="IND" %then %do;

That's perhaps a simpler approach to solving the problem.

Good luck.

sofisaas
Calcite | Level 5

Thank you all very much for helping me. It works when I write %BQUOTE! Thanks againSmiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1780 views
  • 3 likes
  • 4 in conversation