Hi
I am having below datasets,
I want to create a new column called AE and do the calculation of residual ** residual.
I made the following code:
DATA want2;
set want;
AE = residual ** residual;
run;
The column residuals have both negative and positive values. I am not getting value for the negative one after performed residuals ** residual (Square). Anybody can advise what went wrong. I want to square the residual column and store into AE. Please see below screenshot
My second question:
In the above table, you can see the column name called forecast which has both negative and positive values. I want to copy the same value with a positive sign and store into a new column called absolute. ( All negative value should become positive without changing the value and positive remains the same. Ex: -0.005, 0.123 I need 0.005, 0.123 in the new column absolute)
Please advise
I am using SAS Enterprise Guide. I tried with the Query builder also but not successful. Please advise how to do the above two problems in coding as well as using query builder if possible.
Thanks
Dhilip
It seems like SAS has some problems with negativity and exponential. So you can try the following:
DATA want2;
set want;
AE=sign(residual)*abs(residual)**residual;
Absolute = abs(residual);
run;
It seems like SAS has some problems with negativity and exponential. So you can try the following:
DATA want2;
set want;
AE=sign(residual)*abs(residual)**residual;
Absolute = abs(residual);
run;
@sdhilip wrote:
(...)
I made the following code:
DATA want2; set want; AE = residual ** residual; run;
(...) I want to square the residual column and store into AE.
It might be too late, but to store the square of a non-missing value of variable residual in variable AE you should use
AE=residual**2;
or
AE=residual*residual;
whereas residual**residual would be residual raised to the power of residual, which is a very different calculation: compare 8**2=8*8=64 to 8**8=8*8*8*8*8*8*8*8=16777216 and note that (-0.5)**2=0.25, whereas (-0.5)**(-0.5) is not even a real number and therefore results in a missing value in SAS (plus log messages like "Invalid argument ...").
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.