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;

**-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

Share Share Tweet