Calculate Absolute Value in SAS with ABS Function

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:

Sample Dataset

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

data mydata;
input change;

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;
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!
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.

0 Response to "Calculate Absolute Value in SAS with ABS Function"

Post a Comment

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.