
/* varclus procedure : numeric variables를 cluster */

proc varclus data=imputed maxeigen=.7 hi short plots=dendrogram;
   var &inputs brclus1-brclus4 miacctag 
       miphone mipos miposamt miinv 
       miinvbal micc miccbal miccpurc
       miincome mihmown milores mihmval 
       miage micrscor;
   title "Variable Clustering of Imputed Data Set";
run;
*maxeigen= : 각 cluster별 cluster를 split하는 기준;
*outtree=  : tree 프로시져에서 사용할 데이터셋 생성;
*short     : output를 간단하게 출력;


/* output 문장 사용 : variable clustering 결과와 summary 정보 저장 */              
ods html close;
ods output clusterquality=summary
           rsquare=clusters;

proc varclus data=imputed 
             maxeigen=.7 
             short 
             hi;
   var &inputs brclus1-brclus4 miacctag 
       miphone mipos miposamt miinv 
       miinvbal micc miccbal miccpurc
       miincome mihmown milores mihmval 
       miage micrscor;
run;
ods html;

/*hi: requires the clusters at different levels to maintain 
  a hierarchical structure. To draw a tree diagram, 
use the OUTTREE= option and the TREE procedure. */

/* CALL SYMPUT function 사용해서 macro변수 생성 */
/* &NVAR = the number of of clusters       */
/* This is also the number of variables in the analysis, going forward.   */
data _null_;
   set summary;
   call symput('nvar',compress(NumberOfClusters));
run;

title;
proc print data=clusters noobs;
   where NumberOfClusters=&nvar;
   var Cluster Variable RSquareRatio VariableLabel;
run;


/* 각 cluster로 부터 대표변수 선정 : 41개  */
%let reduced=
brclus2 miincome checks ccbal
mmbal income ilsbal posamt
nsfamt cd irabal age
loc sav dda invbal
crscore brclus3 cc brclus1
cashbk miacctag micrscor moved
acctage dirdep savbal ddabal
sdb ccpurc inarea atmamt
phone mmcred hmown inv
depamt brclus4 atm lores
mtg;
