data raw; input Y1 Y2 Y3 Y4 Y5; cards; 5.7 4.3 4.8 4.8 5.7 9.7 5.4 3.1 2.9 2.9 6.2 4.0 5.6 4.3 5.7 13.5 10.1 9.7 8.8 10.6 2.4 2.3 2.8 2.7 3.1 ;
proc print data=raw; %inc '/usr/courses/RS718/distnew.sas'; %distance (data=raw, var=y1-y5, out=rawdist, method=euclid); proc print data=rawdist;
PROC MDS data=rawdist alternate=none coef=identity condition=matrix decimals=3 dim=1 to 2 fit=distance formula=1 inav=data level=absolute out=rawout outres=rawres over=1 pfinal pineigval shape=triangle;
PROC PLOT data=rawout; plot dim2*dim1; PROC PLOT data=rawres; plot fitdata*fitdist;
data corl; /*similarity matrix*/ input V1 V2 V3 V4 V5; cards; 1.000 0.330 0.846 0.666 0.430; 0.330 1.000 0.380 0.902 -0.700; 0.846 0.380 1.000 0.697 0.336; 0.666 0.902 0.697 1.000 -0.338; 0.430 -0.700 0.336 -0.338 1.000 ;
PROC PRINT data=corl; PROC CORR data=raw; /*this his how to get the correlation matrix*/ PROC MDS data=corl alternate=none coef=identity condition=matrix decimals=3 dim=1 to 2 fit=distance formula=1 inav=data level=absolute out=corlout outres=corlres over=1 pfinal pineigval; PROC PLOT data=corlout; plot dim2*dim1; PROC PLOT data=corlres; plot fitdata*fitdist;
/* PART II*/
DATA ELECT; set ssd.elect96; educ=0; if v960610 le 2 then educ=1; if v960610 eq 3 then educ=2; if v960610 eq 4 then educ=3; if v960610 eq 5 then educ=4; if v960610 eq 6 then educ=5; if v960610 eq 7 then educ=6; income=0; if v960701 le 10 then income=1; if v960701 in (11, 12, 13, 14, 15) then income=2; if v960701 in (16, 17, 18) then income=3; if v960701 in (19, 20) then income=4; if v960701 eq 21 then income=5; if v960701 eq 22 then income=6; if v960701 eq 23 then income=7; if v960701 eq 24 then income=8;
PROC CORR; var educ income; DATA CORRELEC; input v1 v2; cards; 1.00000 0.40746 0.40746 1.00000 ; proc print data=correlec; /* Correlation (similarity matrix), metric solution*/
PROC MDS data=correlec alternate=none coef=identity condition=matrix decimals=3 dim=1 to 2 fit=distance formula=1 inav=data level=absolute out=celecout outres=celecres over=1 pfinal pineigval shape=triangle;
PROC PLOT data=celecout; plot dim2*dim1; PROC PLOT data=celecres; plot fitdata*fitdist;
DATA DISTELEC; set elect;
PROC TRANSPOSE out=tranelec; var educ income;
%inc '/usr/courses/RS718/distnew.sas'; %distance (data=tranelec, out=elecdist, method=euclid); PROC PRINT data=elecdist;
/*Dissimilarity matrix (raw data), metric solution*/ PROC MDS data=elecdist alternate=none coef=identity condition=matrix decimals=3 dim=1 to 2 fit=distance formula=1 inav=data level=absolute out=delecout outres=delecres over=1 pfinal pineigval shape=triangle;
PROC PLOT data=delecout; plot dim2*dim1; PROC PLOT data=delecres; plot fitdata*fitdist;
/*Dissimilarity matrix (raw data), nonmetric solution*/ PROC MDS data=elecdist alternate=none coef=identity condition=matrix decimals=3 dim=1 to 2 fit=distance formula=1 inav=data level=ordinal out=nmetout outres=nmetres over=1 pfinal pineigval shape=triangle;
PROC PLOT data=nmetout; plot dim2*dim1; PROC PLOT data=nmetres; plot fitdata*fitdist;
run;
例子