This is not surprising, because SAS calculate the answer with the LOG as below. So LOG of a negative value is not accepted... You have to
handle this yourself!
x ** y = exp(log(x)*y);
To bypass this problem, you need to write a macro in SAS. The macro looks like below:
From http://support.sas.com/kb/24/618.html
%macro nroot(invar,outvar,root);
/* If the root is odd, then take the root of the absolute value and */
/* multiply by the sign of the original value */
if mod(&root,2)=1 then &outvar=sign(&invar)*abs(&invar)**(1/&root);
else do;
/* If the root is even and the original value is negative then */
/* assign a missing value */
if &invar<0 then &outvar=.;
/* Otherwise just take the root */
else &outvar=&invar**(1/&root);
end;
%mend nroot;
/* Use the macro */
data test;
/* Generate some data */
do i=1 to 10;
x=rannor(123);
y=x**3;
/* Take the square root of y and store in y2root */
%nroot(y,y2root,2);
/* Take the cube root of y and store in y3root */
%nroot(y,y3root,3);
output;
end;
run;
Great!Merci!
However, formula like (-9)**(2) and (-9)**(-2) are calculable, while (-9)**(1/2) and (-9)**(-0.5) are not.
So if it is a negative number to the power of some value whose absolute value is less than 1 (taking a root), then SAS cannot calculate it.
If the implicit calculation is x ** y = exp(log(x)*y), then none of these should be calculable.