The HPCLUS Procedure

Getting Started: HPCLUS Procedure

This example shows how to use the HPCLUS procedure to compute clusters of observations in a SAS data set.

Suppose you want to group the observations in inputData, in which the variables are raw measures on interval scales.

The following SAS DATA step creates the SAS data set inputData, which has four variables: the first two variables are the input variables among which x has missing values, the third variable is the frequency variable, and the last variable is an index variable.

data inputData;
   title 'Using PROC HPCLUS to Analyze Data';
   drop n;
   id=1;
   do n=1 to 1000;
      x=2*rannor(12345)+20;
      y=4*rannor(12345)+20;
      freq = 1;
      id = id + 1;
      output;
   end;
   do n=1 to 1000;
      x=3*rannor(12345)+10;
      y=5*rannor(12345)+10;
      freq=2;
     id = id + 1;
   output;
   end;
   do n=1 to 700;
     x=10*rannor(12345);
     y=10*rannor(12345);
     freq=1;
     id = id + 1;
     output;
   end;
	 do n=1 to 200;
     x=.;
     y=10*rannor(12345);
     freq=1;
     id = id + 1;
     output;
   end;
run;

The following statements run PROC HPCLUS and output the results to ODS tables:

proc hpclus data=inputData maxclusters=3;
   input x y;
   freq freq;
run;


Figure 1 shows the values of the parameters that are used in clustering. Because MAXCLUSTERS=3 and the number of clusters is not estimated by default, three clusters are generated. Figure 1 shows the number of clusters and default values for other options.

Figure 1: Model Information

Model Information
Maximum Iteration10
Stop CriterionCluster Change
Stop Criterion Value0
Clusters3
Seed Initialization12345
DistanceEuclidean


Figure 2 shows that the "Number of Observations Used" is less than “Number of Observations Read.” By default, the HPCLUS procedure ignores observations that have missing values, and it does not use them in cluster analysis. The two additional rows, "Sum of Frequencies Read" and “Sum of Frequencies Used,” are displayed when the FREQ statement is specified. They provide information about the frequency values that are read and used.

Figure 2: Number of Observations

Number of Observations Read2900
Number of Observations Used2700
Sum of Frequencies Read3900
Sum of Frequencies Used3700


Figure 3 shows the statistics for each cluster. For each cluster, this table shows the number of observations; the maximum, minimum, and average distances from that cluster’s centroid to the observations in that cluster; the sum of squares error; and the standard deviation. In addition, Figure 3 displays information about the nearest cluster to that cluster and the distance between their centroids.

Figure 3: Cluster Summary

Cluster Summary
ClusterFrequencyDistance from Cluster Centroid
to Observation
SSEStandard
Deviation
Nearest
Cluster
Distance
to
Nearest
Cluster
Centroid
MaximumMinimumAverage
1204231.81740.22225.175377850.86.1745213.8708
2115729.24210.03954.413430848.05.1635113.8708
350130.73570.768810.728975041.212.2386118.2334


Figure 4 shows the sum of squares error (SSE) for each iteration.

Figure 4: Iteration Statistics

Iteration Statistics
Iteration
Number
SSE
0363065
1280328
2236942
3197374
4187016
5184540
6184026
7183921
8183816
9183754
10183740


Figure 5 and Figure 6 show the statistics for each variable in the INPUT statement. Figure 5 shows the variable statistics for all the observations in the input data set, and Figure 6 shows the variable statistics for the observations that belong to a specific cluster.

Figure 5: Descriptive Statistics

Descriptive Statistics
VariableMeanStandard
Deviation
x11.0206488.189686
y10.7565479.180654


Figure 6: Within-Cluster Statistics

Within Cluster Statistics
VariableClusterMeanStandard
Deviation
x19.647110.5402
 219.07755.8267
 3-1.98729.0487
y19.476811.0994
 219.64867.7187
 3-4.56258.4227


Last updated: May 25, 2022