Hello Everyone,
I need someone to check my code and let me know where I am going wrong with it:
options mlogic;
%let decimal= 0 1 2 3 4;
%let orders=INTERNAL FREQ;
%let numerror=0;
%macro salarystats(decimals1=5,order1=PANDA);
%if not &decimals1 in &decimal %then %eval(&numerror+1);
%else %if not &order1 in &orders %then %eval(&numerror+1);
%else %if &numerror lt 1 %then %do;
options nolabel;
title 'Salary Stats';
proc means data=orion.staff maxdec=&decimals order=ℴ
where job_title contains 'Sales';
var salary;
class job_title;
run;
title;
%end;
%else %put What are you trying to use?;
%mend salarystats;
%salarystats()
I keep getting the following error in my log:
MLOGIC(SALARYSTATS): Beginning execution.
MLOGIC(SALARYSTATS): Parameter DECIMALS1 has value 5
MLOGIC(SALARYSTATS): Parameter ORDER1 has value PANDA
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: not &decimals1 in &decimal
ERROR: The macro SALARYSTATS will stop executing.
MLOGIC(SALARYSTATS): Ending execution.
Could someone let me know where I am going wrong with my code?
Thanks!
Alisa
I use sas 9.3. Your code works perfectly now. Thank you! - Linlin
%let decimal= 0 1 2 3 4;
%let orders=INTERNAL FREQ;
%let numerror=0;
%macro salarystats(decimals1=5,order1=PANDA) /minoperator;
%if not &decimals1 in &decimal %then %let numerror=%eval(&numerror+1);
%if not (&order1 in &orders) %then %let numerror=%eval(&numerror+1);
%if &numerror lt 1 %then %do;
options nolabel;
title '????';
proc means data=sashelp.class maxdec=&decimals order=ℴ
var age;
class sex;
run;
title;
%end;
%else %put What are you trying to use?;
%mend salarystats;
%salarystats;
You need to turn on the IN operator if you want to use it. You can add /minoperator to the end of your %MACRO statement.
You also need to do something with the result of the %EVAL() function calls.
Did you mean to use that to increment the error count? if so then you need to use a %LET statement.
Also get rid of the %ELSE's so that both parameters are checked.
%let decimal= 0 1 2 3 4;
%let orders=INTERNAL FREQ;
%let numerror=0;
%macro salarystats(decimals1=5,order1=PANDA) /minoperator;
%if not &decimals1 in &decimal %then %let numerror=%eval(&numerror+1);
%if not &order1 in &orders %then %let numerror=%eval(&numerror+1);
%if &numerror lt 1 %then %do;
options nolabel;
title 'Salary Stats';
proc means data=orion.staff maxdec=&decimals order=ℴ
where job_title contains 'Sales';
var salary;
class job_title;
run;
title;
%end;
%else %put What are you trying to use?;
%mend salarystats;
%salarystats;
Hi Tom,
I ran your code. below is the log file. I replaced the OP's dataset with sashelp.class. Thanks - Linlin
1073 %let decimal= 0 1 2 3 4;
1074 %let orders=INTERNAL FREQ;
1075 %let numerror=0;
1076 %macro salarystats(decimals1=5,order1=PANDA) /minoperator;
1077 %if not &decimals1 in &decimal %then %let numerror=%eval(&numerror+1);
1078 %if not &order1 in &orders %then %let numerror=%eval(&numerror+1);
1079 %if &numerror lt 1 %then %do;
1080 options nolabel;
1081 title 'Salary Stats';
1082 proc means data=sashelp.class maxdec=&decimals order=ℴ
1083 var age;
1084 class sex;
1085 run;
1086 title;
1087 %end;
1088 %else %put What are you trying to use?;
1089 %mend salarystats;
1090 %salarystats;
MLOGIC(SALARYSTATS): Beginning execution.
MLOGIC(SALARYSTATS): Parameter DECIMALS1 has value 5
MLOGIC(SALARYSTATS): Parameter ORDER1 has value PANDA
MLOGIC(SALARYSTATS): %IF condition not &decimals1 in &decimal is TRUE
MLOGIC(SALARYSTATS): %LET (variable name is NUMERROR)
ERROR: A character operand was found in the %EVAL function or %IF condition where
a numeric operand is required. The condition was: not &order1 in &orders
ERROR: The macro SALARYSTATS will stop executing.
MLOGIC(SALARYSTATS): Ending execution.
What version of SAS? I ran using 9.22.
%put sysver=&sysver sysvlong=&sysvlong;
sysver=9.2 sysvlong=9.02.02M3P041310
It was the removal of the extra %ELSE that made it bomb, before I never really tested the other %IF condition because the first one failed.
Enclosing the IN clause in () makes it go away.
%if not (&order1 in &orders) %then ...
I use sas 9.3. Your code works perfectly now. Thank you! - Linlin
%let decimal= 0 1 2 3 4;
%let orders=INTERNAL FREQ;
%let numerror=0;
%macro salarystats(decimals1=5,order1=PANDA) /minoperator;
%if not &decimals1 in &decimal %then %let numerror=%eval(&numerror+1);
%if not (&order1 in &orders) %then %let numerror=%eval(&numerror+1);
%if &numerror lt 1 %then %do;
options nolabel;
title '????';
proc means data=sashelp.class maxdec=&decimals order=ℴ
var age;
class sex;
run;
title;
%end;
%else %put What are you trying to use?;
%mend salarystats;
%salarystats;
Thank you Tom! This worked perfectly!! :smileygrin:
Hi Alisa,
It was Tom's code. Please check one of Tom's posts as correct answer. Thanks - Linlin
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 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.