UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Textbook Examples
Computer-Aided Multivariate Analysis by Afifi and Clark
Chapter 16: Cluster analysis

Page 386 Table 16.2
data companies;
  set "c:\cama3\companies";
run;
proc sql;
create table std_comp as
select *, (ror5 - mean(ror5) )/std(ror5) as std_ror5, 
          (de - mean(de) )/std(de) as std_de,
		  (salesgr5 - mean(salesgr5) )/std(salesgr5) as std_salesgr5,
		  (eps5 - mean(eps5) )/std(eps5) as std_eps5,
		  (npm1 - mean(npm1) )/std(npm1) as std_npm1,
		  (pe - mean(pe) )/std(pe) as std_pe,
		  (payoutr1 - mean(payoutr1) )/std(payoutr1) as std_payoutr1
  from companies;
quit;

proc print data=std_comp;
  var type symbol obsno std_ror5 std_de std_salesgr5 std_eps5 std_npm1 std_pe std_payoutr1;
run;
                                                std_                                    std_
Obs  Type  symbol  obsno  std_ror5   std_de   salesgr5  std_eps5  std_npm1   std_pe   payoutr1

  1    1    dia       1    0.96293  -0.00736   0.42907   0.27749   1.28929  -0.23733   0.15057
  2    1    dow       2    0.96293  -0.00736   0.05048  -0.05684   1.33381  -0.44192  -0.21655
  3    1    stf       3    0.96293  -0.55933  -0.29025   0.22973   1.60093  -0.44192  -0.00701
  4    1    dd        4    0.66060  -0.92731  -0.49216  -0.24788   0.48794  -0.23733   1.28945
  5    1    uk        5   -0.17082  -0.55933  -0.40383  -0.61803   1.06669  -1.05570  -0.66757
  6    1    psm       6   -0.24640  -0.37534  -0.59312   0.15809  -0.22438  -0.85111   0.82860
  7    1    gra       7   -0.20861  -0.37534  -0.83289  -0.73743   0.22082  -0.03273  -0.23085
  8    1    hpc       8   -0.05744  -0.74332  -0.68146  -0.53445   0.08726  -0.23733   0.59662
  9    1    mtc       9   -0.35978  -0.55933  -0.41645  -0.86878  -0.35794   0.17186   1.33015
 10    1    acy      10   -0.20861  -0.55933  -0.59312  -1.07176   0.13178  -0.23733   0.66787
 11    1    cz       11   -0.96444  -0.55933  -0.75718   0.33719  -0.40246  -0.64652   0.65447
 12    1    ald      12   -1.19119  -0.19135  -0.17667  -0.98818   0.35438  -0.64652  -1.08741
 13    1    rom      13   -1.00224  -0.55933  -0.73194  -1.21505   0.57698  -0.64652  -0.73904
 14    1    rei      14   -1.49353  -0.55933   0.23977  -1.94341  -1.33737  -0.03273  -0.18999
 15    2    hum      15   -0.47315   3.67244   2.90251   2.53422   0.66601   2.21779  -0.13474
 16    2    hca      16   -0.58653   0.36062   1.38816   1.23272   1.06669   2.42239  -1.97891
 17    2    nme      17   -0.77549   0.91259   2.76370   1.36406   0.26534   1.80861  -0.84038
 18    2    ami      18   -0.54874   0.72860   0.66884   1.04167   0.75505   1.80861  -0.83807
 19    2    ahs      19    0.92514  -0.74332  -0.10096   0.36108   0.62149   0.78564  -0.96513
 20    3    lks      20    1.79435  -0.00736  -0.18929  -0.18818  -1.24833  -0.44192   1.53644
 21    3    win      21    3.00368  -0.92731  -0.22715  -0.18818  -1.20381  -0.23733   1.37083
 22    3    sgl      22   -0.20861   1.64855  -0.90861   1.32824  -1.47093  -0.85111  -1.70857
 23    3    slc      23   -0.20861   0.72860   0.13882   0.25361  -1.20381  -0.44192  -0.69548
 24    3    kr       24   -0.09524  -0.37534  -0.53002   0.57600  -1.51545  -0.85111   0.37012
 25    3    sa       25   -0.47315   0.54461  -0.65622  -1.03594  -1.55997  -0.64652   1.50460
Page 387 Figure 16.3
data complong;
  set std_comp;
  variable = 1;
  var = std_ror5;
  output;
  variable = 2;
  var = std_de;
  output;
  variable = 3;
  var = std_salesgr5;
  output;
  variable = 4;
  var = std_eps5;
  output;
  variable = 5;
  var = std_npm1;
  output;
  variable = 6;
  var = std_pe;
  output;
  variable = 7;
  var = std_payoutr1;
  output;
run;

data fig163;
  set complong;
  if _n_ le 7;
run;
goptions reset=all hsize = 5in vsize = 8in;
axis1 order=(-3.0 to 2.5 by 0.5) minor = none;
axis2 value=(tick=1 '-ROR5' tick=2 'D/E' tick=3 'SALESGR5' tick = 4 'EPS5' 
             tick = 5 'NPM1' tick = 6 'P/E' tick = 7 '-PAYOUTR1') minor = none;
symbol1 i=line v=dot;
  proc gplot data = fig163;
  plot var*variable / vaxis = axis1 haxis = axis2 vref = 0;
run;
quit;

Page 388 Figure 16.4
data complong1;
  set std_comp;
  variable = 1;
  var = -std_ror5;
  output;
  variable = 2;
  var = std_de;
  output;
  variable = 3;
  var = std_salesgr5;
  output;
  variable = 4;
  var = std_eps5;
  output;
  variable = 5;
  var = std_npm1;
  output;
  variable = 6;
  var = std_pe;
  output;
  variable = 7;
  var = -std_payoutr1;
  output;
run;

data fig164;
  set complong1;
  group = ceil(_n_/7);
  where obsno ge 15 and obsno le 21;
run;

goptions reset=all hsize = 5in vsize = 8in;
axis1 order=(-3.0 to 4.0 by 0.5) minor = none;
axis2 value=(tick=1 '-ROR5' tick=2 'D/E' tick=3 'SALESGR5' tick = 4 'EPS5' 
             tick = 5 'NPM1' tick = 6 'P/E' tick = 7 '-PAYOUTR1') minor = none;
symbol1 i=line v=dot;
proc gplot data = fig164;
  plot var*variable = group / vref = 0 haxis = axis2 vaxis=axis1;
run;
quit;

Page 399 Figure 16.9
proc cluster data = std_comp outtree = tree method = centroid;
  var std_ror5 std_de std_salesgr5 std_eps5 std_npm1 std_pe std_payoutr1;
  id obsno;
run;

proc tree data = tree;
run;

Page 401 Table 16.4
proc fastclus data = std_comp maxclusters = 3 out=test1; 
  var std_ror5 std_de std_salesgr5 std_eps5 std_npm1 std_pe std_payoutr1 ;
  id obsno;
run;

proc print data =test1;
  var type obsno cluster;
run;
Obs    Type    obsno    CLUSTER

  1      1        1        1
  2      1        2        1
  3      1        3        1
  4      1        4        1
  5      1        5        3
  6      1        6        1
  7      1        7        3
  8      1        8        1
  9      1        9        1
 10      1       10        1
 11      1       11        3
 12      1       12        3
 13      1       13        3
 14      1       14        3
 15      2       15        2
 16      2       16        2
 17      2       17        2
 18      2       18        2
 19      2       19        1
 20      3       20        1
 21      3       21        1
 22      3       22        3
 23      3       23        3
 24      3       24        3
 25      3       25        1
Page 403 Figure 16.10
NOTE:  We were unable to reproduce this graph.

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California