ABS: Calculating Absolute Value

How to:

Available Languages: reporting, Maintain

The ABS function returns the absolute value of a number.

Syntax: How to Calculate Absolute Value

ABS(in_value)

where:

in_value

Numeric

Is the value for which the absolute value is returned, the name of a field that contains the value, or an expression that returns the value. If you use an expression, use parentheses as needed to ensure the correct order of evaluation.

Example: Calculating Absolute Value

The COMPUTE command creates the DIFF field, then ABS calculates the absolute value of DIFF:

TABLE FILE SALES
PRINT UNIT_SOLD AND DELIVER_AMT AND
COMPUTE DIFF/I5 = DELIVER_AMT - UNIT_SOLD; AND
COMPUTE ABS_DIFF/I5 = ABS(DIFF);BY PROD_CODE
WHERE DATE LE '1017';
END

The output is:

PROD_CODE  UNIT_SOLD  DELIVER_AMT  DIFF  ABS_DIFF 
---------  ---------  -----------  ----  -------- 
B10               30           30     0         0 
B17               20           40    20        20 
B20               15           30    15        15 
C17               12           10    -2         2 
D12               20           30    10        10 
E1                30           25    -5         5 
E3                35           25   -10        10