turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- ERROR: A Character operand was found in the %Eval ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2011 09:10 AM

Hello,

Can anyone help me to solve this error?

My Code:

%let a = 0.967;

%let b = 0.942;

%let diff = %sysevalf(&a. - &b.);

%Put diff = &diff.;

%Macro test;

%if (0.01 <= &diff. <= 0.01) %then %put &diff.;

%else %put 'Out of Range';

%Mend;

%test;

All I want to do is print the condition result in the log. In this case I

want to print as Out of Range as the value of diff is beyond the boundary

limits.

I am getting this error "A character operand was found in the %EVAL function

or %IF condition where a numeric operand is required. The condition was: (0.

01 <= &diff. <= 0.01)

Thanks,

cbob

Can anyone help me to solve this error?

My Code:

%let a = 0.967;

%let b = 0.942;

%let diff = %sysevalf(&a. - &b.);

%Put diff = &diff.;

%Macro test;

%if (0.01 <= &diff. <= 0.01) %then %put &diff.;

%else %put 'Out of Range';

%Mend;

%test;

All I want to do is print the condition result in the log. In this case I

want to print as Out of Range as the value of diff is beyond the boundary

limits.

I am getting this error "A character operand was found in the %EVAL function

or %IF condition where a numeric operand is required. The condition was: (0.

01 <= &diff. <= 0.01)

Thanks,

cbob

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-04-2011 11:55 AM

Hello Cbob,

Your test is not displayed correctly. Please, check.

Sincerely,

SPR

Your test is not displayed correctly. Please, check.

Sincerely,

SPR

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-04-2011 01:08 PM

> Hello Cbob,

>

> Your test is not displayed correctly. Please, check.

>

> Sincerely,

> SPR

Hello SPR,

For some reason my msg didn't get fully displayed. Below is my actual code

> %let a = 0.967;

> %let b = 0.942;

> %let diff = %sysevalf(&a. - &b.);

> %Put diff = &diff.;

> %Macro test;

> %if (0.01 LE &diff. LE 0.01) %then %put &diff.;

> %else %put 'Out of Range';

> %Mend;

> %test;

>

> All I want to do is print the condition result in the

> log. In this case I

> want to print as Out of Range as the value of diff is

> beyond the boundary

> limits.

>

> I am getting this error "A character operand was

> found in the %EVAL function

> or %IF condition where a numeric operand is required.

> The condition was: (0. 01 LE &diff. LE 0.01)

>

> Your test is not displayed correctly. Please, check.

>

> Sincerely,

> SPR

Hello SPR,

For some reason my msg didn't get fully displayed. Below is my actual code

> %let a = 0.967;

> %let b = 0.942;

> %let diff = %sysevalf(&a. - &b.);

> %Put diff = &diff.;

> %Macro test;

> %if (0.01 LE &diff. LE 0.01) %then %put &diff.;

> %else %put 'Out of Range';

> %Mend;

> %test;

>

> All I want to do is print the condition result in the

> log. In this case I

> want to print as Out of Range as the value of diff is

> beyond the boundary

> limits.

>

> I am getting this error "A character operand was

> found in the %EVAL function

> or %IF condition where a numeric operand is required.

> The condition was: (0. 01 LE &diff. LE 0.01)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-04-2011 01:40 PM

Works fine:

84

85

86 %let a = 0.967;

87 %let b = 0.942;

88 %let diff = %sysevalf(&a. - &b.);

89 %Put diff = &diff.;

diff = 0.025

90 %Macro test;

91 %if (0.01 LE &diff. LE 0.01) %then %put &diff.;

92 %else %put 'Out of Range';

93 %Mend;

94 %test;

'Out of Range'

84

85

86 %let a = 0.967;

87 %let b = 0.942;

88 %let diff = %sysevalf(&a. - &b.);

89 %Put diff = &diff.;

diff = 0.025

90 %Macro test;

91 %if (0.01 LE &diff. LE 0.01) %then %put &diff.;

92 %else %put 'Out of Range';

93 %Mend;

94 %test;

'Out of Range'

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASPhile

03-04-2011 06:41 PM

> Works fine:

>

>

> 84

> 85

> 86 %let a = 0.967;

> 87 %let b = 0.942;

> 88 %let diff = %sysevalf(&a. - &b.);

> 89 %Put diff = &diff.;

> diff = 0.025

> 90 %Macro test;

> 91 %if (0.01 LE &diff. LE 0.01) %then %put

> &diff.;

> 92 %else %put 'Out of Range';

> 93 %Mend;

> 94 %test;

> 'Out of Range'

Thanks for your reply!. It blows up when the diff is negative.Also it is -0.01 in the below lower limit. It works absolutely fine with diff value being positive but if the diff is NEGATIVE it throws error.

%if (-0.01 LE &diff. LE 0.01) %then %put

Thanks,

>

>

> 84

> 85

> 86 %let a = 0.967;

> 87 %let b = 0.942;

> 88 %let diff = %sysevalf(&a. - &b.);

> 89 %Put diff = &diff.;

> diff = 0.025

> 90 %Macro test;

> 91 %if (0.01 LE &diff. LE 0.01) %then %put

> &diff.;

> 92 %else %put 'Out of Range';

> 93 %Mend;

> 94 %test;

> 'Out of Range'

Thanks for your reply!. It blows up when the diff is negative.Also it is -0.01 in the below lower limit. It works absolutely fine with diff value being positive but if the diff is NEGATIVE it throws error.

%if (-0.01 LE &diff. LE 0.01) %then %put

Thanks,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-04-2011 03:48 PM

Hello Cbob,

I personally do not like to use comparison operators for macro variables containing numbers with decimals. Macro variables contain character values so SAS compares character strings but not numbers. So result could depend on how many digits contain decimals you compare.

Sincerely,

SPR

I personally do not like to use comparison operators for macro variables containing numbers with decimals. Macro variables contain character values so SAS compares character strings but not numbers. So result could depend on how many digits contain decimals you compare.

Sincerely,

SPR

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-04-2011 04:58 PM

Your macro %test has a number of problems. I would rather do something like:

%*-- check if value is between min and max, inclusive --*;

**%macro** inRange(value, min=**0.0**, max=**0.1**);

%if %sysevalf((&value) < (&min)) %then**0**;

%else %if %sysevalf((&max) < (&value)) %then**0**;

%else**1**;

**%mend** inRange;

%put %inRange(0.00); %*-- 1 --*;

%put %inRange(0.01); %*-- 1 --*;

%put %inRange(0.10); %*-- 1 --*;

%put %inRange(0.15); %*-- 0 --*;

%*-- check if value is between min and max, inclusive --*;

%if %sysevalf((&value) < (&min)) %then

%else %if %sysevalf((&max) < (&value)) %then

%else

%put %inRange(0.00); %*-- 1 --*;

%put %inRange(0.01); %*-- 1 --*;

%put %inRange(0.10); %*-- 1 --*;

%put %inRange(0.15); %*-- 0 --*;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to chang_y_chung_hotmail_com

03-04-2011 06:33 PM

Chang,

Thanks for your response. I guess what I'm trying to do is to validate whether the difference between the two macro variables a& b is with in the boundary limits(-0.01 to 0.01) or not.

%let a = 0.9377;

%let b = 0.9570;

%let diff = %sysevalf(&a - &b);

%Put diff = &diff;

%Macro test;

%if ((-0.01) LE %sysevalf(&diff.) LE (0.01)) %then %put &diff.;

%else %put 'Out of Range';

%Mend;

%test;

When i run the above code I am getting the below error

ERROR: A Character operand was found in the %Eval function or %IF condition where a numeric operand is required.

Thanks,

Sridhar

Thanks for your response. I guess what I'm trying to do is to validate whether the difference between the two macro variables a& b is with in the boundary limits(-0.01 to 0.01) or not.

%let a = 0.9377;

%let b = 0.9570;

%let diff = %sysevalf(&a - &b);

%Put diff = &diff;

%Macro test;

%if ((-0.01) LE %sysevalf(&diff.) LE (0.01)) %then %put &diff.;

%else %put 'Out of Range';

%Mend;

%test;

When i run the above code I am getting the below error

ERROR: A Character operand was found in the %Eval function or %IF condition where a numeric operand is required.

Thanks,

Sridhar

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-04-2011 11:33 PM

@cbob: Someone has once said:

"Programming is hard enough even when you do know the language. If you don't, I don't see how you have a chance."

After reading Beilei Xu and Lei Zhang's excellent NESUG paper, I think I know what is going on -- that is, the very first part of the comparison:

-0.01 le 0.01

is an error within the implicit %eval between %if and %then. See below for more.

%put %eval(-1); %*-- this is fine. integer --*;

%put %eval(0.01); %*-- error. char(.) found when an integer expected --*;

%put %eval(0.01 le 0.01); %*-- fine. just comparing two text strings --*;

%put %eval(-0.01 le 0.01); %*-- error. minus operator expects an integer --*;

"Programming is hard enough even when you do know the language. If you don't, I don't see how you have a chance."

After reading Beilei Xu and Lei Zhang's excellent NESUG paper, I think I know what is going on -- that is, the very first part of the comparison:

-0.01 le 0.01

is an error within the implicit %eval between %if and %then. See below for more.

%put %eval(-1); %*-- this is fine. integer --*;

%put %eval(0.01); %*-- error. char(.) found when an integer expected --*;

%put %eval(0.01 le 0.01); %*-- fine. just comparing two text strings --*;

%put %eval(-0.01 le 0.01); %*-- error. minus operator expects an integer --*;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

03-06-2011 08:06 PM

Hi.

Try to this:

[pre]

%if %sysevalf((-0.01) LE &diff. LE (0.01)) %then

[/pre]

For the %if ,macro facility will automatically add %eval around the digit ,

So you need to change it into %sysevalf.

Ksharp

Try to this:

[pre]

%if %sysevalf((-0.01) LE &diff. LE (0.01)) %then

[/pre]

For the %if ,macro facility will automatically add %eval around the digit ,

So you need to change it into %sysevalf.

Ksharp

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

04-06-2012 05:43 PM

Thanks Ksharp.

This actually is helping me with the same kind of issue. Saved me tons of research time!

Chris

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cbob

04-06-2012 05:58 PM

Aside from the problem of evaluating non integers with the implied %EVAL. The macro language does not evaluate compound expressions in the same way as in the DATA step.

In the DATA step

if 5 < x < 10 is evaluaged as if 5 < x and x < 10

In the macro language

%if 5 < &x < 10 is evaluated as %if (5 < &x) < 10

Regardless of the value of &X this expression is true as both 0 and 1 are less than 10.

In the macro language always break up compound expressions.

%if 5 < &x and &x < 10 %then ....

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ArtC

04-06-2012 11:16 PM

ArtC,

Love your book on SAS Macro. Wondering how I can get your signature.:smileysilly:

Best Regards,

Haikuo

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Haikuo

04-07-2012 05:30 PM

It is always fun to meet those that read and use the SAS Press books. If you are at SAS Global Forum or PharmaSUG this spring look me up. I would be very happy to meet and talk with you and to of course sign your book.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Haikuo

04-07-2012 06:49 PM

Haikuo: While I haven't written any books that I can sign, look me up, too, if you are going to SGF. I'm doing one presentation with FriedEgg, another with both FriedEgg and KSharp (and a couple of other presentations too) and, of course, ArtC and I will both be presenting at the SAS-L/ SAS Discussion Forums/ sasCommunity.org/ SASProfessionals.net/ SASCanadaCommunity meetup on Tuesday night (April 24th) between 6pm and 8pm.