The HPREDUCE Procedure
Example 9.2 Output a Correlation Matrix to a SAS Data File
This example shows how to output a correlation matrix to a SAS data file. The OUTCP option creates an output data set named corr.
data one;
array x{2};
array c{2};
do i=1 to 2000;
a=int(ranuni(1)*2);
do j=1 to 2;
x{j}=ranuni(1);
c{j}=int(ranuni(1)*2);
end;
output;
end;
run;
title "Output the Correlation Matrix";
proc hpreduce data=one corr outcp=corr;
class a;
reduce unsupervised a x1-x2 /maxsteps=4;
run;
proc print data=corr;
run;
Output 9.2.1 shows the content of the data file generated by PROC HPREDUCE.
Output 9.2.1: Output the Correlation Matrix
| Output the Correlation Matrix |
| Obs | _ID_ | _TYPE_ | _VAR_ | _LEV_ | _vID_ | v1 | v2 | v3 | v4 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | MEAN/FREQ | 1015.00 | 985.00 | 0.50 | 0.50 | |||
| 2 | 2 | N | 2000.00 | 2000.00 | 2000.00 | 2000.00 | |||
| 3 | 3 | CORR | a | 0 | v1 | 1.00 | -1.00 | -0.00 | -0.02 |
| 4 | 4 | CORR | a | 1 | v2 | -1.00 | 1.00 | 0.00 | 0.02 |
| 5 | 5 | CORR | x1 | v3 | -0.00 | 0.00 | 1.00 | -0.01 | |
| 6 | 6 | CORR | x2 | v4 | -0.02 | 0.02 | -0.01 | 1.00 |
The values in the column _VAR_ are the name of the variables. The _LEV_ column shows the name of a CLASS variable’s levels, but is empty for interval variables. Assuming that you have n effects (the total number of interval variables and the levels of CLASS variables), the _vID_ column contains n markers, v1 to vn, where vi denotes the ith effect. The column _TYPE_ defines the role of each row. When the _TYPE_ column shows MEAN/FREQ, the corresponding row contains either the mean for an interval variable or the frequency for a level of a CLASS variable. When the _TYPE_ column shows N, the corresponding row contains the number of samples. And when the _TYPE_ column shows CORR, COV, or SSCP, the corresponding row contains a row of the CORR, COV, or SSCP matrix. In this example, the CORR matrix is , and it resides in the table in row 3 through row 6 and column 7 through column 10.