BookmarkSubscribeRSS Feed
Black
Calcite | Level 5
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?
3 REPLIES 3
Patrick
Opal | Level 21
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;
Doc_Duke
Rhodochrosite | Level 12
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
Patrick
Opal | Level 21
O.K. - But why then works case1 and case4 doesn't?

The only thing I can think of right now would be 'precision'.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1446 views
  • 0 likes
  • 3 in conversation