Sample 50096: Coloring the clusters in a dendrogram
Generate colored clusters in a dendrogram
- PURPOSE:
- The %CLUSTERGROUPS macro enhances dendrograms produced in SAS by adding color to highlight the clusters. You specify the number of clusters desired as input to the macro.
- HISTORY:
-
- REQUIREMENTS:
- Version 9.3 or later of Base SAS software. However, SAS/STAT software (PROC CLUSTER) is generally needed to produce the input data set needed by the macro.
- USAGE:
- Follow the instructions in the Downloads tab of this sample to save the %CLUSTERGROUPS macro definition. Replace the text within quotation marks in the following statement with the location of the %CLUSTERGROUPS macro definition file on your system. In your SAS program or in the SAS editor window, specify this statement to define the %CLUSTERGROUPS macro and make it available for use:
%inc "<location of your file containing the CLUSTERGROUPS macro>";
Following this statement, you can call the %CLUSTERGROUPS macro.
Before running the %CLUSTERGROUPS macro, create the DATA= data set for input to the macro. The easiest way to generate the necessary input data set is to use the OUTTREE= data set from performing a cluster analysis in PROC CLUSTER. The example in the Results tab uses this technique.
The following macro parameter is required:
- NCLUSTERS
- Number of clusters
The following macro parameters are optional:
- DATA=
- SAS data set that can be used by the TREE procedure,
typically created with the OUTTREE= option in PROC CLUSTER.
By default, the macro uses the most recently created SAS data set.
The required variables in the DATA= data set are as follows:
- an ID variable
- NAME_, a character variable giving the name of the node
- _PARENT_, a character variable giving the value of _NAME_ of the parent of the node
- _HEIGHT_, the distance or similarity between the last clusters joined
- ID=
- ID variable from PROC CLUSTER. By default, the macro chooses an ID variable if you do not specify one.
The version of the %CLUSTERGROUPS macro that you are using is displayed in the SAS log when you specify version (or any string) as the first argument. For example:
%CLUSTERGROUPS(version, ...other options...)
The %CLUSTERGROUPS macro attempts to check for a later version of itself. If it is unable to do this (such as if there is no active internet connection available), the macro will issue the following message:
CLUSTERGROUPS: Unable to check for newer version
The computations performed by the macro are not affected by the appearance of this message.
- LIMITATIONS:
- Very little error checking is done. The macro assumes the input data set has the required variables.
This macro cannot be used to analyze an input data set containing multiple BY groups. BY groups processing is not supported.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
- EXAMPLE:
- This example generates an OUTTREE= data set from PROC CLUSTER, which is then used as the DATA=
parameter for the %CLUSTERGROUPS macro.
The macro is called twice, showing a 3-cluster solution and a 4-cluster solution with
colored clusters.
ods html body='b.html' style=htmlblue;
/* Run a cluster analysis and create an OUTTREE= output data set */
proc cluster data=sashelp.mileages(type=distance)
method=average pseudo outtree=tree;
id City;
run;
/* Define the CLUSTERGROUPS macro */
%inc "<location of your file containing the CLUSTERGROUPS macro>";
%clustergroups(nclusters=3)
%clustergroups(nclusters=4, data=tree, id=City)
- RESULTS:
Right-click on the link below and select Save target as... to save
the %CLUSTERGROUPS definition to a file. It is recommended that you name the file
clustergroups.sas
.
Download and save clustergroups.sas
The %CLUSTERGROUPS macro creates a custom template that combines a dendrogram and a blockplot to highlight each of the specified number of clusters with a different color.
Type: | Sample |
Topic: | Analytics ==> Cluster Analysis SAS Reference ==> Procedures ==> CLUSTER SAS Reference ==> Procedures ==> TREE
|
Date Modified: | 2013-06-10 16:50:32 |
Date Created: | 2013-06-03 11:01:37 |
Operating System and Release Information
SAS System | SAS/STAT | z/OS | 9.3 TS1M0 | |
Microsoft® Windows® for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |
Microsoft Windows XP Professional | 9.3 TS1M0 | |
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | |
Windows 7 Enterprise x64 | 9.3 TS1M0 | |
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | |
Windows 7 Home Premium x64 | 9.3 TS1M0 | |
Windows 7 Professional 32 bit | 9.3 TS1M0 | |
Windows 7 Professional x64 | 9.3 TS1M0 | |
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | |
Windows 7 Ultimate x64 | 9.3 TS1M0 | |
Windows Vista | 9.3 TS1M0 | |
Windows Vista for x64 | 9.3 TS1M0 | |
64-bit Enabled AIX | 9.3 TS1M0 | |
64-bit Enabled HP-UX | 9.3 TS1M0 | |
64-bit Enabled Solaris | 9.3 TS1M0 | |
HP-UX IPF | 9.3 TS1M0 | |
Linux | 9.3 TS1M0 | |
Linux for x64 | 9.3 TS1M0 | |
Solaris for x64 | 9.3 TS1M0 | |