前回までに分布特性を把握するためのいくつかの指標を説明し、 その使い方や注意点を喚起した。 今回は、単純集計としてよく利用される頻度集計(クロス集計)の方法を紹介する。
/* Lesson 09-1 */ /* File Name = les0901.sas 06/16/05 */ data gakusei; infile 'all05a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc print data=gakusei(obs=5); run; : proc freq data=gakusei; : 頻度を算出 tables sex jitaku carryer; : 一変量ごとに run; : proc freq data=gakusei; : 頻度を算出 tables sex*jitaku; : 二変量の組み合わせで tables sex*carryer; : tables jitaku*carryer; : run; :
SAS システム 1 23:52 Thursday, June 9, 2005 OBS SEX SHINTYOU TAIJYUU KYOUI JITAKU KODUKAI CARRYER TSUUWA 1 F 145.0 38 . J 10000 . 2 F 146.7 41 85 J 10000 Vodafone 6000 3 F 148.0 42 . J 50000 . 4 F 148.0 43 80 J 50000 DoCoMo 4000 5 F 148.9 . . J 60000 . SAS システム 2 23:52 Thursday, June 9, 2005 Cumulative Cumulative SEX Frequency Percent Frequency Percent ------------------------------------------------- F 112 34.7 112 34.7 M 211 65.3 323 100.0 Frequency Missing = 5 Cumulative Cumulative JITAKU Frequency Percent Frequency Percent ---------------------------------------------------- G 106 36.9 106 36.9 J 181 63.1 287 100.0 Frequency Missing = 41 Cumulative Cumulative CARRYER Frequency Percent Frequency Percent ------------------------------------------------------ DDIp 2 1.9 2 1.9 DoCoMo 49 46.2 51 48.1 J-PHONE 10 9.4 61 57.5 No 4 3.8 65 61.3 Vodafone 16 15.1 81 76.4 au 25 23.6 106 100.0 Frequency Missing = 222 SAS システム 4 23:52 Thursday, June 9, 2005 TABLE OF SEX BY JITAKU SEX JITAKU Frequency| Percent | Row Pct | Col Pct |G |J | Total ---------+--------+--------+ F | 34 | 66 | 100 | 11.93 | 23.16 | 35.09 | 34.00 | 66.00 | | 32.38 | 36.67 | ---------+--------+--------+ M | 71 | 114 | 185 | 24.91 | 40.00 | 64.91 | 38.38 | 61.62 | | 67.62 | 63.33 | ---------+--------+--------+ Total 105 180 285 36.84 63.16 100.00 Frequency Missing = 43 SAS システム 7 23:52 Thursday, June 9, 2005 TABLE OF SEX BY CARRYER SEX CARRYER Frequency| Percent | Row Pct | Col Pct |DDIp |DoCoMo |J-PHONE |No |Vodafone|au | Total ---------+--------+--------+--------+--------+--------+--------+ F | 1 | 21 | 4 | 1 | 9 | 11 | 47 | 0.95 | 20.00 | 3.81 | 0.95 | 8.57 | 10.48 | 44.76 | 2.13 | 44.68 | 8.51 | 2.13 | 19.15 | 23.40 | | 50.00 | 42.86 | 44.44 | 25.00 | 56.25 | 44.00 | ---------+--------+--------+--------+--------+--------+--------+ M | 1 | 28 | 5 | 3 | 7 | 14 | 58 | 0.95 | 26.67 | 4.76 | 2.86 | 6.67 | 13.33 | 55.24 | 1.72 | 48.28 | 8.62 | 5.17 | 12.07 | 24.14 | | 50.00 | 57.14 | 55.56 | 75.00 | 43.75 | 56.00 | ---------+--------+--------+--------+--------+--------+--------+ Total 2 49 9 4 16 25 105 1.90 46.67 8.57 3.81 15.24 23.81 100.00 Frequency Missing = 223 SAS システム 10 23:52 Thursday, June 9, 2005 TABLE OF JITAKU BY CARRYER JITAKU CARRYER Frequency| Percent | Row Pct | Col Pct |DDIp |DoCoMo |J-PHONE |No |Vodafone|au | Total ---------+--------+--------+--------+--------+--------+--------+ G | 1 | 18 | 4 | 0 | 4 | 8 | 35 | 1.05 | 18.95 | 4.21 | 0.00 | 4.21 | 8.42 | 36.84 | 2.86 | 51.43 | 11.43 | 0.00 | 11.43 | 22.86 | | 100.00 | 40.91 | 44.44 | 0.00 | 26.67 | 34.78 | ---------+--------+--------+--------+--------+--------+--------+ J | 0 | 26 | 5 | 3 | 11 | 15 | 60 | 0.00 | 27.37 | 5.26 | 3.16 | 11.58 | 15.79 | 63.16 | 0.00 | 43.33 | 8.33 | 5.00 | 18.33 | 25.00 | | 0.00 | 59.09 | 55.56 | 100.00 | 73.33 | 65.22 | ---------+--------+--------+--------+--------+--------+--------+ Total 1 44 9 3 15 23 95 1.05 46.32 9.47 3.16 15.79 24.21 100.00 Frequency Missing = 233
proc freq data=pat order=freq; : 頻度の高いもの順 tables b1_dncc b1_kobc b1_botc b1_othc b1_ov30; run;(プログラム例 : Pattern11.sas)、 出力結果 : Pattern11.lst
/* Lesson 09-4 */ /* File Name = les0904.sas 06/16/05 */ data gakusei; infile 'all05a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc format; : 階級を作る。class shintyou の意 value clshint low-<150=' -149' : 階級の定義 1 150-<160='150-159' : 2 160-<170='160-169' : 3 170-<180='170-179' : 4 180-high='180- ' : 5 other ='missing'; : 6 run; : proc print data=gakusei(obs=5); run; proc freq data=gakusei; : 頻度を算出 tables shintyou; : 一変量ごとに format shintyou clshint.; : 連続変量をグループ化することの指定 run; : : proc freq data=gakusei; : 頻度を算出 tables sex*shintyou; : 二変量の組合わせで format shintyou clshint.; : 連続変量をグループ化することの指定 run; : : proc sort data=gakusei; : 今までの方法で実現しようとすると by sex; : run; : proc freq data=gakusei; : tables shintyou; : format shintyou clshint.; : 連続変量をグループ化することの指定 by sex; : 性別ごとに run; :
SAS システム 2 23:53 Thursday, June 9, 2005 Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 6 1.9 6 1.9 150-159 47 15.0 53 16.9 160-169 111 35.5 164 52.4 170-179 128 40.9 292 93.3 180- 21 6.7 313 100.0 Frequency Missing = 15 SAS システム 3 23:53 Thursday, June 9, 2005 TABLE OF SEX BY SHINTYOU SEX SHINTYOU Frequency| Percent | Row Pct | Col Pct | -149 |150-159 |160-169 |170-179 |180- | Total ---------+--------+--------+--------+--------+--------+ F | 6 | 45 | 52 | 2 | 0 | 105 | 1.92 | 14.42 | 16.67 | 0.64 | 0.00 | 33.65 | 5.71 | 42.86 | 49.52 | 1.90 | 0.00 | | 100.00 | 95.74 | 47.27 | 1.56 | 0.00 | ---------+--------+--------+--------+--------+--------+ M | 0 | 2 | 58 | 126 | 21 | 207 | 0.00 | 0.64 | 18.59 | 40.38 | 6.73 | 66.35 | 0.00 | 0.97 | 28.02 | 60.87 | 10.14 | | 0.00 | 4.26 | 52.73 | 98.44 | 100.00 | ---------+--------+--------+--------+--------+--------+ Total 6 47 110 128 21 312 1.92 15.06 35.26 41.03 6.73 100.00 Frequency Missing = 16 SAS システム 6 23:53 Thursday, June 9, 2005 ------------------------------- SEX=' ' -------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 160-169 1 100.0 1 100.0 Frequency Missing = 4 SAS システム 7 23:53 Thursday, June 9, 2005 -------------------------------- SEX=F --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ -149 6 5.7 6 5.7 150-159 45 42.9 51 48.6 160-169 52 49.5 103 98.1 170-179 2 1.9 105 100.0 Frequency Missing = 7 SAS システム 8 23:53 Thursday, June 9, 2005 -------------------------------- SEX=M --------------------------------- Cumulative Cumulative SHINTYOU Frequency Percent Frequency Percent ------------------------------------------------------ 150-159 2 1.0 2 1.0 160-169 58 28.0 60 29.0 170-179 126 60.9 186 89.9 180- 21 10.1 207 100.0 Frequency Missing = 4
/* Lesson 09-5 */ /* File Name = les0905.sas 06/16/05 */ data gakusei; infile 'all05a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; proc format; value clshint low-<150=' -149' 150-<160='150-159' 160-<170='160-169' 170-<180='170-179' 180-high='180- ' other ='missing'; run; proc print data=gakusei(obs=5); run; proc tabulate data=gakusei; : 要約統計量の表の作成 class sex jitaku; : 特性変数であることの宣言 var kodukai; : 集計する変量名 tables kodukai*(n mean std),sex*jitaku; : 表示内容、分類変量名 run; : proc tabulate data=gakusei; : class shintyou sex; : var taijyuu; : tables taijyuu*(n mean std),shintyou*sex; : format shintyou clshint.; : 連続変量をグループ化することの指定 run; :
SAS システム 2 23:53 Thursday, June 9, 2005 ---------------------------------------------------------------------- | | SEX | | |---------------------------------------------------| | | F | M | | |-------------------------+-------------------------| | | JITAKU | JITAKU | | |-------------------------+-------------------------| | | G | J | G | J | |----------------+------------+------------+------------+------------| |KODUKAI|N | 32.00| 64.00| 70.00| 111.00| | |--------+------------+------------+------------+------------| | |MEAN | 78437.50| 35117.19| 83900.00| 25972.97| | |--------+------------+------------+------------+------------| | |STD | 60032.75| 30802.07| 53760.65| 34801.90| ---------------------------------------------------------------------- SAS システム 3 23:53 Thursday, June 9, 2005 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | -149 | 150-159 | 160-169 | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | F | F | M | F | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 5.00| 35.00| 2.00| 34.00| | |--------+------------+------------+------------+------------| | |MEAN | 41.80| 46.96| 54.50| 51.31| | |--------+------------+------------+------------+------------| | |STD | 2.59| 4.37| 9.19| 3.50| ---------------------------------------------------------------------- (CONTINUED) SAS システム 4 23:53 Thursday, June 9, 2005 ---------------------------------------------------------------------- | | SHINTYOU | | |---------------------------------------------------| | | 160-169 | 170-179 | 180- | | |------------+-------------------------+------------| | | SEX | SEX | SEX | | |------------+-------------------------+------------| | | M | F | M | M | |----------------+------------+------------+------------+------------| |TAIJYUU|N | 58.00| 0.00| 126.00| 21.00| | |--------+------------+------------+------------+------------| | |MEAN | 58.61| .| 62.97| 67.36| | |--------+------------+------------+------------+------------| | |STD | 7.67| .| 7.42| 7.81| ----------------------------------------------------------------------
data gakusei; infile 'all05a.prn' firstobs=2; input sex $ shintyou taijyuu kyoui jitaku $ kodukai carryer $ tsuuwa; dekasa=shintyou+taijyuu+kyoui; : 変量間の加減乗除 kyo_2=kyoui**2; : 二乗 kyo_sr=sqrt(kyoui); : ルート
[算術演算子]
[数値関数]
data randnum; do i=1 to 200; x=rannor(12345); output; end; run;プログラム例 : les0906.sas、 出力結果 : les0906.lst
[乱数関数] : 乱数を生成する関数
data math; infile 'foo.dat' lrecl=230;
data math; infile 'foo.dat' lrecl=230 truncover;
input kamoku $ 2 kesseki $ 3 k_code $ 10-11 t_score 12-14 s_scor01 103-104 s_scor02 105-106 s_scor03 107-108 s_scor04 109-110 ;
data math; infile 'foo.dat' firstobs=4;