format _SEGMNT_ CLS_QJP_. distance best12.; *************************************; *** begin scoring code for clustering; *************************************; label _SEGMNT_ = "Cluster ID" Distance = 'Distance to Cluster Seed'; drop _nonmiss; _nonmiss = n( G , SLG , AVG , OBP , AB , R , H , H2 , H3 , HR , RBI , BB , SO , SB ); if _nonmiss = 0 then do; _SEGMNT_ = .; distance = .; end; else do; array _CLScads[3] _temporary_; drop _clus; do _clus = 1 to 3; _CLScads[_clus] = 0; end; if n(G) then do; _CLScads[1] + (G - 151.33333333 )**2; _CLScads[2] + (G - 83.171875 )**2; _CLScads[3] + (G - 128 )**2; end; if n(SLG) then do; _CLScads[1] + (SLG - 0.4797091707 )**2; _CLScads[2] + (SLG - 0.4021044991 )**2; _CLScads[3] + (SLG - 0.4456851266 )**2; end; if n(AVG) then do; _CLScads[1] + (AVG - 0.2864124264 )**2; _CLScads[2] + (AVG - 0.253640907 )**2; _CLScads[3] + (AVG - 0.2709364507 )**2; end; if n(OBP) then do; _CLScads[1] + (OBP - 0.3537374757 )**2; _CLScads[2] + (OBP - 0.3120291057 )**2; _CLScads[3] + (OBP - 0.3451151436 )**2; end; if n(AB) then do; _CLScads[1] + (AB - 576.15686275 )**2; _CLScads[2] + (AB - 241.5625 )**2; _CLScads[3] + (AB - 431.21212121 )**2; end; if n(R) then do; _CLScads[1] + (R - 91.176470588 )**2; _CLScads[2] + (R - 30.34375 )**2; _CLScads[3] + (R - 60.393939394 )**2; end; if n(H) then do; _CLScads[1] + (H - 165.17647059 )**2; _CLScads[2] + (H - 61.578125 )**2; _CLScads[3] + (H - 116.6969697 )**2; end; if n(H2) then do; _CLScads[1] + (H2 - 33.568627451 )**2; _CLScads[2] + (H2 - 12.84375 )**2; _CLScads[3] + (H2 - 23.96969697 )**2; end; if n(H3) then do; _CLScads[1] + (H3 - 2.9803921569 )**2; _CLScads[2] + (H3 - 1.1875 )**2; _CLScads[3] + (H3 - 2.0303030303 )**2; end; if n(HR) then do; _CLScads[1] + (HR - 23.901960784 )**2; _CLScads[2] + (HR - 6.765625 )**2; _CLScads[3] + (HR - 15.848484848 )**2; end; if n(RBI) then do; _CLScads[1] + (RBI - 86.215686275 )**2; _CLScads[2] + (RBI - 30.015625 )**2; _CLScads[3] + (RBI - 61.696969697 )**2; end; if n(BB) then do; _CLScads[1] + (BB - 60.843137255 )**2; _CLScads[2] + (BB - 20.875 )**2; _CLScads[3] + (BB - 50.96969697 )**2; end; if n(SO) then do; _CLScads[1] + (SO - 99.882352941 )**2; _CLScads[2] + (SO - 48.234375 )**2; _CLScads[3] + (SO - 83 )**2; end; if n(SB) then do; _CLScads[1] + (SB - 13.68627451 )**2; _CLScads[2] + (SB - 3.265625 )**2; _CLScads[3] + (SB - 5.8181818182 )**2; end; _SEGMNT_ = 1; distance = _CLScads[1]; do _clus = 2 to 3; if _CLScads[_clus] < distance then do; _SEGMNT_ = _clus; distance = _CLScads[_clus]; end; end; distance = sqrt(distance*14/_nonmiss); end; *** impute missing values; label _Impute_ = 'Number of Imputed Values'; _impute_ = 14 - _nonmiss; if _impute_=0 then goto _CLSclex; if _nonmiss = 0 then do; *** for all missing, impute mean; G = 116.65540541 ; SLG = 0.4385639515 ; AVG = 0.2687902342 ; OBP = 0.3337788768 ; AB = 399.14864865 ; R = 58.006756757 ; H = 109.56756757 ; H2 = 22.466216216 ; H3 = 1.9932432432 ; HR = 14.695945946 ; RBI = 56.445945946 ; BB = 41.358108108 ; SO = 73.783783784 ; SB = 7.4256756757 ; end; *** end all missing; else do; *** impute=nearseed; array _CLScasd [3,14] _temporary_ ( /* cluster 1 */ 151.33333333 0.4797091707 0.2864124264 0.3537374757 576.15686275 91.176470588 165.17647059 33.568627451 2.9803921569 23.901960784 86.215686275 60.843137255 99.882352941 13.68627451 /* cluster 2 */ 83.171875 0.4021044991 0.253640907 0.3120291057 241.5625 30.34375 61.578125 12.84375 1.1875 6.765625 30.015625 20.875 48.234375 3.265625 /* cluster 3 */ 128 0.4456851266 0.2709364507 0.3451151436 431.21212121 60.393939394 116.6969697 23.96969697 2.0303030303 15.848484848 61.696969697 50.96969697 83 5.8181818182 ); retain _CLScasd; if nmiss(G) then G = _CLScasd[_SEGMNT_,1 ]; if nmiss(SLG) then SLG = _CLScasd[_SEGMNT_,2 ]; if nmiss(AVG) then AVG = _CLScasd[_SEGMNT_,3 ]; if nmiss(OBP) then OBP = _CLScasd[_SEGMNT_,4 ]; if nmiss(AB) then AB = _CLScasd[_SEGMNT_,5 ]; if nmiss(R) then R = _CLScasd[_SEGMNT_,6 ]; if nmiss(H) then H = _CLScasd[_SEGMNT_,7 ]; if nmiss(H2) then H2 = _CLScasd[_SEGMNT_,8 ]; if nmiss(H3) then H3 = _CLScasd[_SEGMNT_,9 ]; if nmiss(HR) then HR = _CLScasd[_SEGMNT_,10 ]; if nmiss(RBI) then RBI = _CLScasd[_SEGMNT_,11 ]; if nmiss(BB) then BB = _CLScasd[_SEGMNT_,12 ]; if nmiss(SO) then SO = _CLScasd[_SEGMNT_,13 ]; if nmiss(SB) then SB = _CLScasd[_SEGMNT_,14 ]; end; *** end nearseed; _CLSclex:; ***********************************; *** end scoring code for clustering; ***********************************;