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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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