Recently I hit a very simple and surprising SAS issue, namely calculating powers for negative base like:
(-1)**(1/3) or (-1)**0.2345 etc.
For this simple SAS (EG 4.3) program:
I got the following in the LOG:
17 data a;
NOTE: Invalid argument(s) to the exponential operator "**".
Of course, I understand that SAS goes into a trouble calculating LOG from negative numbers, and I can use a logic to overcome it. However, even a table calculator crunches these powers easily.
I'm pretty sure that this issue has been raised in the past. I would like to know if there is a SAS function to calculate such powers?
Thanks. I think that the following construction:
works for most of the cases except for power=1/2n, n=1,.... Simple logic can be used to catch these exceptions and assign missing to y.
I don't see why there is an issue about "inverse evens" like powers 1/2, 1/4.
Once the sign(x) is extracted the exponentiation with any fractional power of the abs(x) positive number, delivers a single positive answer.
As I suggested, removing that minus removes the problem.
As suggested 10 years ago by Ian Whitlock
Is it not appropriate to remove the minus (as in sign(x) *abs(x) **power )?
(sorry I'm just perplexed at the logic that suggests there is logical difference between 1/2 and 1/3 in the arithmetic when I would see no similar difference between .24, .25, .26 and .3, .3333)
The fractional powers serve a purpose for me that makes complex numbers seem alien. Most meaningful example occurs when generating periodic rates in compound interest for example providing monthly and quarterly equivalent rates for annual data. Nominally the method discussed above could provide a derived rate over a third of a year but not for half or quarter.
Must be something wrong with my model which is approximately like:
Interval_rate = (1+annual)**[1/interval] -1 ;
If "annual" is very bad (1+annual) might become negative
If interval is 3 or 4 I expect logically similar results and cannot just ban intervals which are even.
I imagine there are models in other fields which need to solve this kind of arithmetic in a consistent way without just saying
There is an obvious problem with this formula for example for interval=4. To solve it, it is necessary to return to the method used to derive this formula and to see what will be for even intervals. I do not know how this formula has been derived and hence can not be more specific.
the problem is with the data being out of valid range for the model.
Even though "odd" fraction powers might provide a real root there are also "imaginary" roots (- since you wish to be rigorously mathematical I think that was the terminology when I learnt complex maths in school....) but mine was not imaginary but a real problem: re-basing a measure of the rate of increase (or decline).. So as that terminology switched from increase to decline, the negative sign was removed to "outside" the calculation and into the terminology...