Help using Base SAS procedures

Need a code check on Parameter Validations

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

Need a code check on Parameter Validations

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


Accepted Solutions
Solution
‎04-01-2012 12:15 AM
Super Contributor
Posts: 1,636

Re: Need a code check on Parameter Validations

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


All Replies
Super User
Super User
Posts: 7,046

Re: Need a code check on Parameter Validations

Posted in reply to InfoAlisaA

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;

Super Contributor
Posts: 1,636

Re: Need a code check on Parameter Validations

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.

Super User
Super User
Posts: 7,046

Re: Need a code check on Parameter Validations

What version of SAS?  I ran using 9.22.

%put sysver=&sysver sysvlong=&sysvlong;

sysver=9.2 sysvlong=9.02.02M3P041310

Super User
Super User
Posts: 7,046

Re: Need a code check on Parameter Validations

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

Solution
‎04-01-2012 12:15 AM
Super Contributor
Posts: 1,636

Re: Need a code check on Parameter Validations

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;

Frequent Contributor
Posts: 90

Need a code check on Parameter Validations

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

Super Contributor
Posts: 1,636

Re: Need a code check on Parameter Validations

Posted in reply to InfoAlisaA

Hi Alisa,

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 288 views
  • 0 likes
  • 3 in conversation