SPSS Numeric Functions

SPSS supports these numeric functions in the global scope.


General Syntax

Arguments

Most numeric functions take a singular argument. The exceptions are:

For the statistical functions (i.e. CFVAR, MAX, MEAN, MEDIAN, MIN, SD, SUM, and VARIANCE), variable lists are also a valid way to specify the multiple arguments.

.N Suffix

Statistical functions (i.e. CFVAR, MAX, MEAN, MEDIAN, MIN, SD, SUM, and VARIANCE) silently ignore invalid values. One option for mitigation of programming errors is to require some number of the arguments be valid. These functions can all be called with a .N suffix that specifies this number.

CFVAR, SD, and VARIANCE each already require 2 valid values. All other statistical functions have an effective default of 1.


Abs

The ABS function returns the absolute value of any numeric expression.


Arcos

The ARCOS function returns the inverse cosine of any numeric expression. This value is not allowed to be greater than 1 or less than -1. The returned value is expressed in radians.

Note: unsupported in SPSS.

Note: also callable as ACOS in PSPP.


Arsin

The ARSIN function returns the inverse sine of any numeric expression. This value is not allowed to be greater than 1 or less than -1. The returned value is expressed in radians.

Note: also callable as ASIN in PSPP.


Artan

The ARTAN function returns the inverse tangent of any numeric expression. The returned value is expressed in radians.

Note: also callable as ATAN in PSPP.


CfVar

The CFVAR function returns the coefficient of variance among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as CFVAR.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


Cos

The COS function returns the cosine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.


Exp

The EXP function returns e raised to the power of any numeric expression.


Lg10

The LG10 function returns the base-10 logarithm of any numeric expression. This value is not allowed to be 0 or less.


Ln

The LN function returns the natural logarithm of any numeric expression. This value is not allowed to be 0 or less.


LnGamma

The LNGAMMA function returns the logarithm of the complete Gamma function of any numeric expression. This value is not allowed to be 0 or less.


Max

The MAX function returns the maximum value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MAX.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Min

The MIN function returns the minimum value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MIN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Mean

The MEAN function returns the average value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MEAN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Median

The MEDIAN function returns the median value among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as MEDIAN.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Mod

The MOD function returns the remainder from a division of any two numeric expressions. The first value is the dividend and the second is the divisor. The divisor is not allowed to be 0.


Range

The RANGE function takes a variable and 1 or more pairs of low-high value pairs. It returns 1 for all cases with a value within the inclusive range of low to high.

data list free / ID (F2) Score (F2).
begin data
1, 10, 2, 20, 3, 30, 4, 40, 5, 50, 6, 60, 7, 70, 8, 80, 9, 90
end data.
compute InRange=range(Score,30,40,70,80).
list all.

ID

Score

!InRange

1

10

0

2

20

0

3

30

1

4

40

1

5

50

0

6

60

0

7

70

1

8

80

1

9

90

0


Rnd

The RND function rounds any numeric expression to the nearest integer. In all cases, rounding ties are broken away from 0.

If the optional second argument is specified, RND rounds to the nearest multiple of that value. This value is not allowed to be 0.

compute rounded_gpa = rnd(true_gpa, 0.1).

If the optional third argument is specified, the threshold for rounding up is lowered by N bits.

* Mathematically, CONST = 1.5.
* Per the 64-bit floating point number implementation, CONST = 1.499999999999998.
compute CONST = 9.62 - 5.82 - 9.21 + 6.91.

* This returns 1.
compute bad_round = rnd(CONST, 1, 0).

* This returns 2.
compute good_round = rnd(CONST, 1, 4).

If the third argument is not specified, RND defaults to the system setting for FIZZBITS (i.e. SET FIZZBITS 0.), which has defaulted to 6 since SPSS 17.


SD

The SD function returns the standard deviation among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as SD.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


Sin

The SIN function returns the sine of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians.


Sqrt

The SQRT function returns the square root of any numeric expression. This value is not allowed to be negative.


String

The STRING function returns the string representation of a numeric expression. The second argument is the format to be applied before conversion.

For example, string(123.45, F5.1) returns "123.4".

See also the NUMBER function.


Sum

The SUM function returns the sum of 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as SUM.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value.


Tan

The TAN function returns the tangent of any numeric expression. The input value is interpreted as radians, and and returned value is expressed in radians. The function returns a system missing value for any values too close to an odd multiple of π/2.

Note: unsupported in SPSS.


Trunc

The TRUNC function floors any numeric expression to the next integer toward 0.

If the optional second argument is specified, TRUNC floors to the next multiple of that value. This value is not allowed to be 0.

If the optional third argument is specified, a threshold for rounding up by N bits is introduced.

* Mathematically, CONST = 1.5.
* Per the 64-bit floating point number implementation, CONST = 1.499999999999998.
compute CONST = 9.62 - 5.82 - 9.21 + 6.91.

* This returns 1.4.
compute bad_floor = rnd(CONST, 0.1, 0).

* This returns 1.5.
compute good_floor = rnd(CONST, 0.1, 5).

If the third argument is not specified, RND defaults to the system setting for FIZZBITS (i.e. SET FIZZBITS 0.), which has defaulted to 6 since SPSS 17.


Uniform

The UNIFORM function selects from a random uniform distribution from 0 to N. Note that a random seed must be set first.

Below is a demonstration for how an SRS sample can be drawn.

set seed=random.
compute rand=uniform(100000).
rank variables=rand /rank into rrand.
compute sample=0.
if (rrand le 200) sample=1.


Variance

The VARIANCE function returns the variance among 2 or more numeric expressions. Invalid values are ignored silently.

To denote a minimum number of valid values, call the function as VARIANCE.N, where N is the minimum number. If N + 1 or more values are invalid, the function returns a system missing value. By default, this number is 2.


CategoryRicottone

SPSS/NumericFunctions (last edited 2023-06-10 13:00:34 by DominicRicottone)