Calculate Absolute Value in SAS with ABS Function

Deepanshu Bhalla Add Comment

In SAS, you can use the ABS function to calculate the absolute value of a number.

Syntax of ABS Function

The syntax of ABS function is as follows:

ABS(numeric_variable)
Sample Dataset

Let's create a sample SAS dataset for demonstration purpose.

data mydata;
input change;
cards;
2
3
-2
-3
0
;
run;

The following code uses the ABS function to calculate the absolute value of each value in the "change" column.

data example;
set mydata;
abs_change = abs(change);
proc print;
run;
Calculate Absolute Value in SAS
  • -2 has been changed to 2.
  • -3 has been changed to 3.
How to Use ABS Function in a SAS Macro

To calculate the absolute value in a SAS Macro, you need to enclose the ABS function within the %SYSFUNC function.

%let myvalue=-3.4;
%put absolute value is %sysfunc(abs(&myvalue.));

LOG: absolute value is 3.4

Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "Calculate Absolute Value in SAS with ABS Function"
Next → ← Prev