/*---------------------------------------------------------- %mds ( level = ) %plot( vaxis = , haxis = ) %gplot( vaxis = , haxis = ) -----------------------------------------------------------*/ options nosource ; data mileages( type = distance ) ; input ( atlanta chicago denver houston losangel miami newyork sanfran seattle washdc ) ( 5. ) @56 city $15. ; cards; 0 atlanta 587 0 chicago 1212 920 0 denver 701 940 879 0 houston 1936 1745 831 1374 0 los angeles 604 1188 1726 968 2339 0 miami 748 713 1631 1420 2451 1092 0 new york 2139 1858 949 1645 347 2594 2571 0 san francisco 2182 1737 1021 1891 959 2734 2408 678 0 seattle 543 597 1494 1220 2300 923 205 2442 2329 0 washington d.c. ; run ; data nation( type = distance ) ; input ( v1 - v12 ) ( 5. ) @62 nation$ ; cards; 0 ブラジル 4.83 0 コンゴ 5.28 4.56 0 キューバ 3.44 5.00 5.17 0 エジプト 4.72 4.00 4.11 4.78 0 仏国 4.50 4.83 4.00 5.83 3.44 0 印度 3.83 3.33 3.61 4.67 4.00 4.11 0 イスラエル 3.50 3.39 2.94 3.83 4.22 4.50 4.83 0 日本 2.39 4.00 5.50 4.39 3.67 4.11 3.00 4.17 0 中国 3.06 3.39 5.44 4.39 5.06 4.50 4.17 4.61 5.72 0 ソ連 5.39 2.39 3.17 3.33 5.94 4.28 5.94 6.06 2.56 5.00 0 米国 3.17 3.50 5.11 4.28 4.72 4.00 4.44 4.28 5.06 6.67 3.56 0 ユーゴスラビア ; run ; %macro morsedat ; data morse ; infile "d:\waseda\mds\morse.csv" dsd ; length id $4 ; input a b c d e f g h i j k l m n o p q r s t u v w x y z _1 - _9 _0 ; array aaa ( 36 ) a b c d e f g h i j k l m n o p q r s t u v w x y z _1 - _9 _0 ; call vname( aaa( _n_ ), id ) ; run ; data upper ; set morse ; length id $4 ; array aaa ( 36 ) a -- z _1 - _9 _0 ; _r_ = _n_ ; do _c_ = ( _r_ + 1 ) to 36 ; upper = aaa( _c_ ) ; id = put( _r_, z2. ) || put( _c_, z2. ) ; output ; end ; keep id upper ; run ; proc sort data = upper ; by id ; run ; data lower ; set morse ; length id $4 ; array aaa ( 36 ) a -- z _1 - _9 _0 ; _r_ = _n_ ; do _c_ = 1 to ( _r_ - 1 ) ; lower = aaa( _c_ ) ; id = put( _c_, z2. ) || put( _r_, z2. ) ; output ; end ; keep id lower ; run ; proc sort data = lower ; by id ; run ; data ave ; merge upper lower ; by id ; dif = upper - lower ; ave = mean( lower, upper ) ; _c_ = input( substr( id, 1, 2 ), 2. ) ; _r_ = input( substr( id, 3, 2 ), 2. ) ; keep ave dif _r_ _c_ ; run ; data diag ; set morse ; array aaa ( 36 ) a -- z _1 - _9 _0 ; _r_ = _n_ ; do _c_ = 1 to 36 ; if _r_ = _c_ then do ; ave = aaa( _c_) ; output ; end ; end ; keep _r_ _c_ ave ; run ; data avelow ; set ave diag ; run ; proc sort data = avelow ; by _r_ _c_ ; run ; data signal( type = distance ) ; length signal $8 ; array aaa ( 36 ) a b c d e f g h i j k l m n o p q r s t u v w x y z _1 - _9 _0 ; keep signal a b c d e f g h i j k l m n o p q r s t u v w x y z _1 - _9 _0 ; retain a -- z _1 - _9 _0 ; set avelow ; if first._r_ then row + 1 ; by _r_ ; if first._r_ then do _i_ = 1 to 36 ; aaa( _i_ ) = . ; end ; aaa( _c_ ) = ave ; call label( aaa( row ), signal ) ; if last._r_ then output ; run ; %mend morsedat ; %macro morslab ; A = "A*-" N = "N-*" B = "B-***" O = "O---" C = "C-*-*" P = "P*--*" D = "D-**" Q = "Q--*-" E = "E*" R = "R*-*" F = "F**-*" S = "S***" G = "G--*" T = "T-" H = "H****" U = "U**-" I = "I**" V = "V***-" J = "J*---" W = "W*--" K = "K-*-" X = "X-**-" L = "L*-**" Y = "Y-*--" M = "M--" Z = "Z--**" _1 = "1*----" _6 = "6-****" _2 = "2**---" _7 = "7--***" _3 = "3***--" _8 = "8---**" _4 = "4****-" _9 = "9----*" _5 = "5*****" _0 = "0-----" %mend morslab ; %macro mds3 ; proc mds data = nation out = out outres = res similar ; id nation ; run ; proc plot data = out ; plot dim2 * dim1 $ nation / box vref = 0 href = 0 ; run ; quit ; axis1 length = 70 pct ; axis2 length = 50 pct ; symbol1 v = circle i = none h = 0.5 ; proc gplot data = res ; plot fitdata * fitdist / fr vaxis = axis1 haxis = axis2 ; run ; quit ; %mend mds3 ; %macro mds2( data = signal ) ; proc mds data = signal similar out = outmds outres = res pdata ; var a b c d e f g h i j k l m n o p q r s t u v w x y z _1 - _9 _0 ; label %morslab ; run ; proc plot data = outmds vtoh = 1 nolegend ; plot dim2 * dim1 = ' ' $ _label_ / box vpos = 30 hpos = 90 ; where _type_ = 'CONFIG' ; run ; %plotit( data = outmds(where=(_type_='CONFIG')), datatype = mds, gopplot = cback=white, color = black, colors = black blue red, SYMVAR=,PLACE=0, labfont = simplex, labsize=2, labelvar = _label_, vtoh = 1.75 ); axis1 length = 70 pct ; axis2 length = 50 pct ; symbol1 v = circle i = none h = 0.5 ; proc gplot data = res ; plot fitdata * fitdist / fr vaxis = axis1 haxis = axis2 ; run ; quit ; %mend mds2 ; %macro mds1 ; proc mds data = mileages level = absolute out = outmds outres = res pfinal pdata ; id city; run ; %print( outmds ); %print( res ); %mend mds1 ; %macro plot1 ; proc plot data = outmds vtoh = 1.7 ; plot dim2 * dim1 $ city / box haxis = by 500 vaxis = by 500 ; where _type_ = 'CONFIG' ; run ; proc plot data = res ; plot fitdata * fitdist / box hpos = 60 vpos = 20 ; run ; %mend plot1 ; %macro gplot1 ; proc datasets library = work ; delete gseg / mt = cat ; run ; data x ; set outmds( where=(_type_='CONFIG') ) ; run ; symbol1 v = none i = none ; %gplotlab( data = x , id = city, dim1 = dim1, dim2 = dim2, fontolab = swiss, /* ラベルのフォント. */ sizeolab = 0.8, /* ラベルのサイズ */ plot = y , /* グラフ印刷の有無: Y | N */ device = win , /* 出力デバイス: WIN | WINPRTM */ horigin = 0 cm, /* グラフ印刷時の左余白 */ vorigin = 0 cm, /* グラフ印刷時の下余白 */ hlength = 9cm, /* グラフ印刷時の水平軸の長さ */ vlength = 6cm, /* グラフ印刷時の垂直軸の長さ */ horder = %str( order = ( -1500 to 1500 by 500 ) ) , vorder = %str( order = ( -1000 to 1000 by 500 ) ) , dim1lab = f = swiss h = 0.5 "DIM1", dim2lab = f = swiss h = 0.5 "DIM2" ) axis1 length = 6 cm ; axis2 length = 6 cm ; symbol1 v = circle i = join h = 0.6 ; proc sort data = res out = temp ; by fitdata ; run ; proc gplot data = temp ; plot fitdata * fitdist / fr vaxis = axis1 haxis = axis2 ; run ; quit ; %mend gplot1 ; options source ;