Language Reference


CORR Function

CORR (x <, method> <, excludemiss> );

The CORR function computes a sample correlation matrix for data. The arguments are as follows:

x

specifies an $n\times p$ numerical matrix of data. The CORR function computes a $p\times p$ correlation matrix of the data.

method

specifies the method used to compute the correlation matrix. The following strings are valid:

"Pearson"

specifies the computation of Pearson product-moment correlations. The correlations range from $-1$ to 1. This is the default value.

"Hoeffding"

specifies the computation of Hoeffding’s D statistics, scaled to range between $-0.5$ and 1.

"Kendall"

specifies the computation of Kendall’s tau-b coefficients based on the number of concordant and discordant pairs of observations. Kendall’s tau-b ranges from $-1$ to 1.

"Spearman"

specifies the computation of Spearman correlation coefficients based on the ranks of the variables. The correlations range from $-1$ to 1.

excludemiss

specifies how missing values are handled. The following values are valid:

"listwise"

specifies that observations with missing values are excluded from the analysis. This is the default value.

"pairwise"

specifies that all nonmissing pairs of values for each pair of variables are included in the statistical computations.

The method and excludemiss arguments are not case-sensitive. The first four characters are used to determine the value. For example, "LIST" and "listwise" specify the same option.

The CORR function computes a sample correlation matrix for data, as shown in the following example:

x = {5 1 10,
     6 2 3,
     6 8 5,
     6 7 9,
     7 2 13};
corr = corr(x);
spearman = corr(x, "spearman");
print corr, spearman;

Figure 25.79: Correlation Matrices

corr
1 0.1091089 0.265165
0.1091089 1 -0.289319
0.265165 -0.289319 1

spearman
1 0.3441236 0.2236068
0.3441236 1 -0.410391
0.2236068 -0.410391 1



The CORR function behaves similarly to the CORR procedure. In particular, the documentation for the CORR procedure in the Base SAS Procedures Guide: Statistical Procedures includes details about the various correlation statistics.

The CORR function also handles missing values in the same way as the CORR procedure. In particular, be aware that specifying excludemiss="pairwise" might result in a correlation matrix that is not nonnegative definite.

You can use the ROWNAME= and COLNAME= options in the MATTRIB statement or the PRINT statement to associate names of variables to rows and columns of the correlation matrix. For example, if the names of the variables in the previous example are X1, X2, and X3, then the following statements associate those names with the matrix returned by the CORR function:

varnames = {"X1" "X2" "X3"};
mattrib corr     rowname=varnames colname=varnames
        spearman rowname=varnames colname=varnames;
print corr, spearman;

Figure 25.80: Correlation Matrices with Named Rows and Columns

corr
  X1 X2 X3
X1 1 0.1091089 0.265165
X2 0.1091089 1 -0.289319
X3 0.265165 -0.289319 1

spearman
  X1 X2 X3
X1 1 0.3441236 0.2236068
X2 0.3441236 1 -0.410391
X3 0.2236068 -0.410391 1



Prior to SAS/IML 9.22, there was a module named CORR in the IMLMLIB library. This module has been removed.