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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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;

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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;

Linlin
Lapis Lazuli | Level 10

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.

Tom
Super User Tom
Super User

What version of SAS?  I ran using 9.22.

%put sysver=&sysver sysvlong=&sysvlong;

sysver=9.2 sysvlong=9.02.02M3P041310

Tom
Super User Tom
Super User

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

Linlin
Lapis Lazuli | Level 10

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;

InfoAlisaA
Calcite | Level 5

Thank you Tom! This worked perfectly!! :smileygrin:

Linlin
Lapis Lazuli | Level 10

Hi Alisa,

It was Tom's code. Please check one of Tom's posts as correct answer.  Thanks - Linlin

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 7 replies
  • 918 views
  • 0 likes
  • 3 in conversation