Help using Base SAS procedures

Why SAS can't output (-3)**(-3) in do loop?

Reply
Occasional Contributor
Posts: 13

Why SAS can't output (-3)**(-3) in do loop?

First program:
data c;
x=-3;
y=x**x;
run;
/* we can get y=-0.037037037 by first program. */

Second program:
data a;
do x=-5 to 5 by 0.01;
y=x**x;
output;
end;
run;
/* From x=-4.99 to 0, the y value is empty. Even x=-3, the y is empty too. */

How could this happen?
Could anyone help to interpret this?
Respected Advisor
Posts: 3,894

Re: Why SAS can't output (-3)**(-3) in do loop?

That looks like a bug to me.
Report it to SAS TechSupport.

data c;
y=-3.1**-3.1;
put 'Case 1: ' y=;

x=3.1;
y=x**-3.1;
put 'Case 2: ' y=;

x=-3.1;
y=-3.1**x;
put 'Case 3: ' y=;

x=-3.1;
y=x**-3.1;
put 'Case 4: ' y=;
run;
Trusted Advisor
Posts: 2,113

Re: Why SAS can't output (-3)**(-3) in do loop?

Actually, it's not a bug. y**x, where y is a negative number, is called a discontinuous function -- it is not defined for every value on the real line. For instance, (-4)**2 is well defined (16), but (-4)**(1/2) (e.g. the square root of -4) is unknown.

In Black's case, my guess is that when (-3)**(-3) is rendered, SAS gets the exact value 3, but there is some rounding in the repeated additions in the do-loop, and then the discontinuous nature of using a negative base comes into play. SAS gives an invalid argument error message for the results it could not compute.

Doc Muhlbaier
Duke
Respected Advisor
Posts: 3,894

Re: Why SAS can't output (-3)**(-3) in do loop?

O.K. - But why then works case1 and case4 doesn't?

The only thing I can think of right now would be 'precision'.
Ask a Question
Discussion stats
  • 3 replies
  • 98 views
  • 0 likes
  • 3 in conversation