I have a macro paragram.
%macro test(param);
proc print data=customer;
where customer_group="¶m";
%if ¶m=A members %then %do;
title "the most abudant group is %upcase(¶m)";
%end;
%else %do;
title "the least abudant group is %upcase(¶m)";
%end;
var name gender age customer_group;
run;
%mend test;
options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&least);
But I get an error:
MPRINT(TEST): where customer_group="Internet/Catalog Customers"; ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: ¶m=A members
Have you tried changing
%if ¶m=A members %then %do;
to
%if "¶m"=A members %then %do;
?
Have you tried changing
%if ¶m=A members %then %do;
to
%if "¶m"=A members %then %do;
?
Thanks. It works. I just also wonder if I pass the the variable directly. Say
%test(least);
Rather than
%test(&least);
Is it possible?
dont know. I'm probably more of a SAS newb than you 🙂 I just did a little pattern recognition on your code. In some places the variable had quotes around it and in others it didn't. seemed reasonable to assume that was where the problem was.
The reason I asked is I want to reference the parameter into the tite statement.
title "the least abudant group is %upcase(¶m)"
I want to replace the word "least" in the title statement with the param as they are same words.
Pass a parameter in macro
When this is resolved Internet/Catalog Customers
your program tries to do a division,
I almost always double quote my macro comparison arguments.
HAVE
====
Up to 40 obs WORK.CUSTOMER total obs=5
Obs NAME SEX CUSTOMER_GROUP
1 Alfred M Store Customers
2 Alice F Store Customers
3 Barbara F Internet/Catalog Customers
4 Carol F Store Customers
5 Henry M Store Customers
WANT
====
the least abudant group is INTERNET/CATALOG CUSTOMERS
Obs NAME SEX AGE CUSTOMER_GROUP
3 Barbara F 13 Internet/Catalog Customers
BUT I GET THE ERRO
MPRINT(TEST): where customer_group="Internet/Catalog Customers";
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
is required. The condition was: ¶m=A members
WITH THIS CODE
==============
%macro test(param);
proc print data=customer;
where customer_group="¶m";
%if ¶m=A members %then %do;
title "the most abudant group is %upcase(¶m)";
%end;
%else %do;
title "the least abudant group is %upcase(¶m)";
%end;
var name gender age customer_group;
run;
%mend test;
options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&least);
WORKING CODE
============
Change
%if ¶m =A members %then %do;
to
%if "¶m" ="A members" %then %do;
Also she need a run;quit;
FULL SOLUTION
=============
data customer( keep=name sex age customer_group);
set sashelp.class(obs=5);
if name='Barbara' then customer_group ='Internet/Catalog Customers';
else customer_group='Store Customers';
run;quit;
%macro test(param);
proc print data=customer;
where customer_group="¶m";
%if "¶m" ="A members" %then %do;
title "the most abudant group is %upcase(¶m)";
%end;
%else %do;
title "the least abudant group is %upcase(¶m)";
%end;
var name sex age customer_group;
run;quit;
run;
%mend test;
options mprint mlogic;
%let least=Internet/Catalog Customers;
%test(&least);
I am not sure what the value is in this whole bit of code. The only part which actually changes is the word most or least, so why not evaluate than and drop all the rest of it? E.g.
data _null_; call symputx('word',ifc("¶m."="A members","most","least")); run; title "The &word. abundant group is %upcase(¶m.)"; proc print data=customer; where customer_group="¶m."; var name gender age customer_group; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.