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_v1v2v3v4
11MEAN/FREQ   1015.00985.000.500.50
22N   2000.002000.002000.002000.00
33CORRa0v11.00-1.00-0.00-0.02
44CORRa1v2-1.001.000.000.02
55CORRx1 v3-0.000.001.00-0.01
66CORRx2 v4-0.020.02-0.011.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 4 times 4, and it resides in the table in row 3 through row 6 and column 7 through column 10.

Last updated: May 25, 2022