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
- /
- SAS Procedures
- /
- Why SAS can't output (-3)**(-3) in do loop?

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-25-2008 03:15 AM

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?

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?

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

Posted in reply to Black

12-25-2008 07:43 PM

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;

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;

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

Posted in reply to Black

12-26-2008 02:52 PM

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

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

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

Posted in reply to Doc_Duke

12-26-2008 07:56 PM

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

The only thing I can think of right now would be 'precision'.

The only thing I can think of right now would be 'precision'.