CORR (x <, method> <, excludemiss> );
The CORR function computes a sample correlation matrix for data. The arguments are as follows:
specifies an numerical matrix of data. The CORR function computes a correlation matrix of the data.
specifies the method used to compute the correlation matrix. The following strings are valid:
specifies the computation of Pearson product-moment correlations. The correlations range from to 1. This is the default value.
specifies the computation of Hoeffding’s D statistics, scaled to range between and 1.
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 to 1.
specifies the computation of Spearman correlation coefficients based on the ranks of the variables. The correlations range from to 1.
specifies how missing values are handled. The following values are valid:
specifies that observations with missing values are excluded from the analysis. This is the default value.
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;
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;
Prior to SAS/IML 9.22, there was a module named CORR in the IMLMLIB library. This module has been removed.