Composing numeric expressions

The following elements can be part of a numeric expression:

There are two situations where the result of the evaluation of an expression is undefined and SPSS returns a SYSMIS value:

If an operation implies a missing value and 0, the result is not always SYMIS, for instance [mv is a missing value] 0*mv, 0/mv will produce 0 (as do 0**mv or MOD(0,mv).

Numerical Operators
+ add
- subtract
* multiply
/ divide
** exponentiation
Functions
Name ExplanationExample, comment
ABS(arg) Absolute valueABS(G1-G2)
RND(arg) RoundingRND(PNB/HABIT)
TRUNC(arg) Integer part
(truncate)
TRUNC(PNB/HABIT)
MOD(arg,arg)moduloMOD(PNB/HABIT,10)
SQRT(arg)Square rootSQRT(GNP)
EXP(arg)e to the power of arg
LG10(arg)logarithm base 10
LN(arg)Natural log
ARSIN(arg)arc sineresult in radians
ARTAN(arg)arc tangentresult in radians
SIN(arg)sineresult in radians
COS(arg)cosineresult in radians
This list is not exhaustive.

arg may be a simple argument or a numeric expression. The result

Statistical functions

Statistical functions compute for each case a summary statistic across all variables specified as argument to the function (varlis).

SUM (varlis) Sum
MEAN(varlis) Mean
SD(varlis) Standard Deviation
VARIANCE(varlis)Variance
CFVAR(varlis) Coefficient of variation
MIN(varlis) Minimum
MAX(varlis) Maximum
Missing value functions
VALUE(varnam) User missing values are treated as non-missing
NMISS(varlis) Number of missing values in varlis
NVALID(varlis) Number of valid values in varlis

See also the SYSMIS() and MISSING() logical functions explained here with logical expressions

Other functions

SPSS has a large number of specialized functions, useful when working with time data (time and date oriented functions and lags), string and conversion functions, as well as functions dealing with random variables and (statistical) distributions. The table below shows just a few, common ones as an example.

LAG(arg,n) Create a lagged time series (n is the lag).
DATEDIFFDifference in days between two dates.
XDATE.WKDAYDay of the week
RV.NORMAL(m,sd)Normally distributed random numbers with mean=m and standard deviation=sd
RV.CHISQ(df)Random numbers based on chi-square distribution with df degrees of freedom
CDF.LAPLACECumulative Laplace distribution