DATA Step, Macro, Functions and more

A character operand was found in the %EVAL function or %IF condition where a numeric operand is req

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

A character operand was found in the %EVAL function or %IF condition where a numeric operand is req

%let chg_pct=%sysevalf(100*((&N_NEW-&N_OLD)/&N_OLD));

%if &chg_pct. >= &mint. and &chg_pct. <= &maxt. %then

%do;
        proc sql;
                UPDATE test1.TC_INPUTS2
                SET status = 'pass'
                WHERE vendorname = &VENDOR. and testcasenum=3.1
                AND tablename = &cur_tblname1
                AND columnname = &cur_colname1;
        quit;
%end;
%else
%do;
        proc sql;
                UPDATE test1.TC_INPUTS2
                SET status = 'fail'
                                     
                WHERE vendorname = &VENDOR. and testcasenum=3.1
                AND tablename = &cur_tblname1
                AND columnname = &cur_colname1;
        quit;
%end;

 

 

here is my code. pls help me to get it corrected.

the value of chg_pct is resolved to : -33.33333333

and value of N_NEW is resolved to : 2

and value of N_OLD is resolved to : 3

and value of mint is resolved to : 0

and value of maxt is resolved to : 0


Accepted Solutions
Solution
‎03-30-2016 10:31 AM
Super User
Posts: 5,518

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

The problem arises on your %IF/%THEN statement.  Macro language applies %EVAL to all %IF conditions, and the decimal point in &CHG_PCT causes a problem for %EVAL.  Switch to:

 

%if %sysevalf(&chg_pct. >= &mint.) and %sysevalf(&chg_pct. <= &maxt.) %then

 

That should take care of it.

 

Just a side note ... perhaps these data values are just for testing.  But note that the %IF conditions would only be true when &chg_pct = 0.

 

 

View solution in original post


All Replies
Super User
Super User
Posts: 7,997

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

Not sure why you are using macro language to do "data" processing.  Better to use Base SAS which is for this:

proc sql;
  UPDATE test1.TC_INPUTS2
  SET status = 'pass'
  WHERE vendorname = &VENDOR. and testcasenum=3.1
       AND tablename = &cur_tblname1
       AND columnname = &cur_colname1
   and 100 * ((&n_new.-&n_old.)/&n_old.) between &mint. and &maxt.
;
quit;

It sounds to me like you are in all kinds of a pickle trying to force your code through macro language.  Look at what you have to start with, and what you want out, its almost 99% guarenteed that you can do what you want in Base SAS without any macro language.

Occasional Contributor
Posts: 5

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Hi,

actually Iam using this macro becoz I am using loop which can take more than one value and i have to perform the same operations everytime .

Super User
Super User
Posts: 7,997

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

Again, its all in the thinking about the problem, logically, from a Base SAS perspective, and then adding macro in when needed, not the other way round.  Maybe post some of what you are trying to do, for instance:

1) Create a dataset of your looping data from the database - no need to query this once per iteration, do it once, and store it in a dataset

2) Look at this dataset, perform your calculations here - no need to do them in macro code

3) Merge this information with your working data

No need for looping.

 

Occasional Contributor
Posts: 5

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

what i actually need is how to compare the 2 variables where one of them is -ve decimal and other one is integer.

Super User
Super User
Posts: 7,997

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

Will try to get an example when I get home, but why not:

proc sql;
  insert into TEST1.TC_INPUTS2
  select  case when int(YOUR_VARIABLE)=YOUR_VARIABLE then "Pass"
            else "Fail" end 
  from    HAVE;
quit;

 

Super User
Posts: 5,441

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

Avoid whenever possible mixing numerical values with calculations and comparisons in macros.

Do the calculation and comparison in a data _null_ step, and generate a flag macro variable instead (call symput).

 

And to further simplify your code, the only thing differing is the word pass/fail. Perhaps generate that directly, and avoiding the %if as well.

Data never sleeps
Occasional Contributor
Posts: 5

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

i need the macro to be in my code as I have used do looping to get the values from the sql DB and for each itteration it is taking one column and performing operations on that. here Iam doing implicit pass through
Solution
‎03-30-2016 10:31 AM
Super User
Posts: 5,518

Re: A character operand was found in the %EVAL function or %IF condition where a numeric operand is

Posted in reply to PN00429118

The problem arises on your %IF/%THEN statement.  Macro language applies %EVAL to all %IF conditions, and the decimal point in &CHG_PCT causes a problem for %EVAL.  Switch to:

 

%if %sysevalf(&chg_pct. >= &mint.) and %sysevalf(&chg_pct. <= &maxt.) %then

 

That should take care of it.

 

Just a side note ... perhaps these data values are just for testing.  But note that the %IF conditions would only be true when &chg_pct = 0.

 

 

☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 801 views
  • 1 like
  • 4 in conversation