GVARCLUS Procedure

Example 18.2 Output a Covariance Matrix to a SAS Data File

This example shows how to output a covariance matrix to a SAS data file. The OUTCP= option creates an output data table named mylib.cov.

The following DATA step generates a data table that has 2,000 observations and contains both interval variables (x1–x2) and nominal variables (a, c1, and c2):

data mylib.data1;
    array x{2};
    array c{2};
    do i=1 to 2000;
        a=int(rand('UNIFORM')*2);
        do j=1 to 2;
            x{j}=rand('UNIFORM');
            c{j}=int(rand('UNIFORM')*2);
       end;
       output;
    end;
run;

These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.

The following statements invoke the GVARCLUS procedure:

 title  "Output of Covariance Matrix";

 proc gvarclus data=mylib.data1 maxiter=4 outcp=mylib.cov;
     input c1 c2 /level=nominal;
     input x1 x2 /level=interval;
 run;

 proc print data=mylib.cov;
 run;

Output 18.2.1 shows the content of the data file that PROC GVARCLUS generates.

Output 18.2.1: Output of Covariance Matrix

Output of Covariance Matrix

Obs_ID__TYPE__VAR__vID_v1v2v3v4v5v6
11MEAN/FREQ  0.490.501012.00988.001031.00969.00
22N  2000.002000.002000.002000.002000.002000.00
33COVx1v1166.9110.159.68-9.68-4.974.97
44COVx2v210.15171.144.39-4.390.39-0.39
55COVc1 0v39.684.39499.93-499.933.31-3.31
66COVc1 1v4-9.68-4.39-499.93499.93-3.313.31
77COVc2 0v5-4.970.393.31-3.31499.52-499.52
88COVc2 1v64.97-0.39-3.313.31-499.52499.52


The _VAR_ column displays the names of all variables and the levels of the nominal variables. Assuming that you have n effects (the total number of interval variables and the levels of categorical 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 displays MEAN/FREQ, the corresponding row contains either the mean for an interval variable or the frequency for a level of a nominal variable. When the _TYPE_ column displays N, the corresponding row contains the number of samples. And when the _TYPE_ column displays COV, the corresponding row contains a row of the covariance matrix. In this example, the covariance matrix is 4 times 4, and it resides in the table in rows 3–6 and columns 7–10.

Last updated: September 04, 2026