CORRELATION Procedure

Example 9.1 Computing Correlations between Two Sets of Variables

(View the complete code for this example.)

The following statements create the data table Setosa, which contains measurements for four iris parts from Fisher’s iris data (1936): sepal length, sepal width, petal length, and petal width. The data table has been altered to contain some missing values.

*------------------- Data on Iris Setosa --------------------*
| The data table contains 50 iris specimens from the species |
| Iris Setosa with the following four measurements:          |
| SepalLength (sepal length)                                 |
| SepalWidth  (sepal width)                                  |
| PetalLength (petal length)                                 |
| PetalWidth  (petal width)                                  |
| Certain values were changed to missing for the analysis.   |
*------------------------------------------------------------*;
data mylib.Setosa;
  input SepalLength SepalWidth PetalLength PetalWidth @@;
  label sepallength='Sepal Length in mm.'
        sepalwidth='Sepal Width in mm.'
        petallength='Petal Length in mm.'
        petalwidth='Petal Width in mm.';
  datalines;
50 33 14 02  46 34 14 03  46 36 .  02
51 33 17 05  55 35 13 02  48 31 16 02
52 34 14 02  49 36 14 01  44 32 13 02
50 35 16 06  44 30 13 02  47 32 16 02
48 30 14 03  51 38 16 02  48 34 19 02
50 30 16 02  50 32 12 02  43 30 11 .
58 40 12 02  51 38 19 04  49 30 14 02
51 35 14 02  50 34 16 04  46 32 14 02
57 44 15 04  50 36 14 02  54 34 15 04
52 41 15 .   55 42 14 02  49 31 15 02
54 39 17 04  50 34 15 02  44 29 14 02
47 32 13 02  46 31 15 02  51 34 15 02
50 35 13 03  49 31 15 01  54 37 15 02
54 39 13 04  51 35 14 03  48 34 16 02
48 30 14 01  45 23 13 03  57 38 17 03
51 38 15 03  54 34 17 02  51 37 15 04
52 35 15 02  53 37 15 02
;

The following statements request a correlation analysis between two sets of variables, the sepal measurements (length and width) and the petal measurements (length and width):

title 'Fisher (1936) Iris Setosa Data';
proc correlation data=mylib.Setosa sscp cov;
   var  sepallength sepalwidth;
   with petallength petalwidth;
run;

The "Simple Statistics" table in Output 9.1.1 displays univariate statistics for the analysis variables that are specified in the VAR and WITH statements.

Output 9.1.1: Simple Statistics

Fisher (1936) Iris Setosa Data

The CORRELATION Procedure

Simple Statistics
VariableNMeanStd DevSumMinimumMaximumLabel
PetalLength4914.714291.62019721.0000011.0000019.00000Petal Length in mm.
PetalWidth482.520831.03121121.000001.000006.00000Petal Width in mm.
SepalLength5050.060003.52490250343.0000058.00000Sepal Length in mm.
SepalWidth5034.280003.79064171423.0000044.00000Sepal Width in mm.


When the WITH statement is specified together with the VAR statement, the CORRELATION procedure produces rectangular matrices for statistics such as covariances and correlations. The matrix rows correspond to the variables specified in the WITH statement (PetalLength and PetalWidth), and the matrix columns correspond to the variables specified in the VAR statement (SepalLength and SepalWidth). The CORRELATION procedure uses the WITH variable labels to label the matrix rows.

The SSCP option requests a table of the uncorrected sum of squares and crossproducts matrix, and the COV option requests a table of the covariance matrix.

The sum of squares and crossproducts statistics for each pair of variables are computed by using observations that have nonmissing row and column variable values. The "Sums of Squares and Crossproducts" table in Output 9.1.2 displays the crossproduct, the sum of squares for the row variable, and the sum of squares for the column variable for each pair of variables.

Output 9.1.2: Sums of Squares and Crossproducts

Sums of Squares and Crossproducts
SSCP / Row Var SS / Col Var SS
 SepalLengthSepalWidth
PetalLength
Petal Length in mm.
36214.0000
10735.0000
123793.0000
24756.0000
10735.0000
58164.0000
PetalWidth
Petal Width in mm.
6113.0000
355.0000
121356.0000
4191.0000
355.0000
56879.0000


The variances are computed by using observations that have nonmissing values for the analysis variables. The "Variances and Covariances" table in Output 9.1.3 displays the covariance, variance for the row variable, variance for the column variable, and associated degrees of freedom for each pair of variables.

Output 9.1.3: Variances and Covariances

Variances and Covariances
Covariance / Row Var Variance / Col Var Variance / DF
 SepalLengthSepalWidth
PetalLength
Petal Length in mm.
1.270833
2.625000
12.333333
48
1.363095
2.625000
14.605442
48
PetalWidth
Petal Width in mm.
0.911348
1.063387
11.801418
47
1.048316
1.063387
13.627216
47


When there are missing values in the analysis variables, the "Pearson Correlation Coefficients" table in Output 9.1.4 displays the correlation, the p-value under the null hypothesis of zero correlation, and the number of observations for each pair of variables.

Output 9.1.4: Pearson Correlation Coefficients

Pearson Correlation Coefficients
Prob > |r| under H0: Rho=0
Number of Observations
 Sepal Length
in mm.
Sepal Width in
mm.
PetalLength
Petal Length in mm.
0.2233
0.1229
49
0.2201
0.1285
49
PetalWidth
Petal Width in mm.
0.2573
0.0775
48
0.2754
0.0582
48


Last updated: June 22, 2026