Statistical functions

  • Each argument to a statistical function (expression, variable name, or constant) must be separated by a comma.
  • The .n suffix can be used with all statistical functions to specify the number of valid arguments. For example, MEAN.2(A,B,C,D) returns the mean of the valid values for variables A, B, C, and D only if at least two of the variables have valid values. The default for n is 2 for SD, VARIANCE, and CFVAR and 1 for other statistical functions. If the number specified exceeds the number of arguments in the function, the result is system-missing.
  • The keyword TO can be used to refer to a set of variables in the argument list.

SUM. SUM(numexpr,numexpr[,..]). Numeric. Returns the sum of its arguments that have valid, nonmissing values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

MEAN. MEAN(numexpr,numexpr[,..]). Numeric. Returns the arithmetic mean of its arguments that have valid, nonmissing values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

MEDIAN. MEDIAN(numexpr,numexpr[,..]). Numeric. Returns the median (50th percentile) of its arguments that have valid, nonmissing values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

SD. SD(numexpr,numexpr[,..]). Numeric. Returns the standard deviation of its arguments that have valid, nonmissing values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

VARIANCE. VARIANCE(numexpr,numexpr[,..]). Numeric. Returns the variance of its arguments that have valid values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

CFVAR. CFVAR(numexpr,numexpr[,...]). Numeric. Returns the coefficient of variation (the standard deviation divided by the mean) of its arguments that have valid values. This function requires two or more arguments, which must be numeric. You can specify a minimum number of valid arguments for this function to be evaluated.

MIN. MIN(value,value[,..]). Numeric or string. Returns the minimum value of its arguments that have valid, nonmissing values. This function requires two or more arguments. For numeric values, you can specify a minimum number of valid arguments for this function to be evaluated.

MAX. MAX(value,value[,..]). Numeric or string. Returns the maximum value of its arguments that have valid values. This function requires two or more arguments. For numeric values, you can specify a minimum number of valid arguments for this function to be evaluated.

Example

COMPUTE maxsum=MAX.2(SUM(var1 TO var3), SUM(var4 TO var6)).
  • MAX.2 will return the maximum of the two sums provided that both sums are nonmissing.
  • The .2 refers to the number of nonmissing arguments for the MAX function, which has only two arguments because each SUM function is considered a single argument.
  • The new variable maxsum will be nonmissing if at least one variable specified for each SUM function is nonmissing.