GVARCLUS Procedure

Getting Started: GVARCLUS Procedure

Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.

This example demonstrates how you can use the GVARCLUS procedure to cluster variables into homogeneous groups and construct a hierarchy.

The following DATA step generates a data table and loads the table into your CAS session. The table consists of 100 observations and 20 continuous variables (x1x20). There are two groups of five variables, and 10 variables that are randomly generated from an uniform distribution. The initial variables for each group, x1 and x6, are independently generated from a normal distribution. Two of the variables from each group are linearly correlated to their initial variables, and the other two variables have a nonlinear relationship.

data mylib.getStarted;
    array x{20}  x1-x20;
    call streaminit(12345);
    do i = 1 to 100;
        x1=rand('NORMAL'); x2=0.9*x1+0.2; x3=0.7*x1+0.6; x4=x3*x2*x1; x5=x1*x1*x1;
        x6=rand('NORMAL'); x7=0.9*x6+0.2; x8=0.7*x6+0.6; x9=x8*x6; x10=x6*x6*x6;
        do j= 11 to 20;
            x{j} = rand('UNIFORM');
        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 execute the GVARCLUS algorithm on the mylib.getStarted data table:

 proc gvarclus data=mylib.getStarted mincluster=2 maxsteps=8
               rho=0.8 outtree=mylib.dendrogram;
     input x1-x20 / level=interval;
 run;

The INPUT statement defines the input variables x1 to x20 as interval variables. The MINCLUSTER= option in the PROC GVARCLUS statement specifies the minimum number of clusters as 2, so the clustering process stops when the number of clusters is less than or equal to 2. The MAXSTEPS= option specifies the maximum number of steps in the clustering process as 8. The RHO= option specifies a value of 0.8, which determines the sequence of regularization parameters left-bracket 0.8 Superscript 1 Baseline comma 0.8 squared comma 0.8 cubed comma ellipsis right-bracket that are used in each step sequentially. The OUTTREE= option creates the mylib.dendrogram table to contain information about the tree structure of hierarchical clustering.

The output from this analysis is presented in Figure 1 and Figure 2.

Figure 1 displays the "Number of Observations" tables. This table shows that all 100 observations in the data table are used in the analysis.

Figure 1: Number of Observations

The GVARCLUS Procedure

Number of Observations Read100
Number of Observations Used100


Figure 2 shows the "Cluster Summary" table, which shows the cluster structure in each step. The variable (or level for nominal variables) is assigned to a unique cluster in each step, and the clusters from sequential steps are nested to form a hierarchical structure.

Figure 2: Cluster Summary

Cluster Summary
ParameterStep 1Step 2Step 3Step 4Step 5Step 6Step 7Step 8
x11193551668196109
x22193551668196109
x33193551668196109
x44203652678296109
x55213753688397109
x66223854698498110
x76223854698498110
x86223854698498110
x97233955708598110
x108244054698498110
x119254156718699111
x12102642577287100112
x13112743587388101113
x14122844597489102114
x15132945607590103115
x16143046617691104116
x17153147627792105117
x18163248637893106118
x19173349647994107119
x20183450658095108120


You can define a dendrogram in the Graph Template Language (GTL) and display the hierarchical clustering results from the GVARCLUS algorithm.

The following code copies mylib.dendrogram into the Work library:

data outtree;
    set mylib.dendrogram;
run;

The following code defines the parent node, child node and the height in the dendrogram through the DENDROGRAM statement in GTL. The dendrogram is then plotted using the SGRENDER procedure.

 proc template;
     define statgraph dendrogram;
     begingraph;
     layout overlay;
     dendrogram nodeID=_CHILD_ parentID=_PARENT_ clusterheight=_HEIGHT_;
     endlayout;
     endgraph;
 end;

 proc sgrender data=outtree template=dendrogram;
 run;

Figure 3 shows the dendrogram.

Figure 3: Hierarchical Clustering

 Hierarchical Clustering


Last updated: August 06, 2026