BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sdhilip
Quartz | Level 8

Hi

 

I am having below datasets,

 

 

I want to create a new column called AE and do the calculation of residual ** residual.

 

Capture.JPG

 

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

 

Capture.JPG

 

 

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
heffo
Pyrite | Level 9

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;

View solution in original post

2 REPLIES 2
heffo
Pyrite | Level 9

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;
FreelanceReinh
Jade | Level 19



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

 

Hi @sdhilip (and @heffo),

 

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 ...").

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1386 views
  • 0 likes
  • 3 in conversation