/* Lesson 12-01 */ /* File Name = les1201.sas 01/12/21 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'StatM20/les1201-Results.txt' new; data gakusei; infile 'StatM20/StudAll20e.csv' firstobs=8 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku : $10. kodukai carryer $ tsuuwa; proc print data=gakusei(obs=5); run; title '*** データ全体を対象に ***'; : 出力に説明を追記する proc freq data=gakusei; table sex; run; proc means data=gakusei; var shintyou taijyuu; run; ods listing; : グラフをキャラクタープロットで出力する場合 ods graphics off; : proc univariate data=gakusei plot; var shintyou taijyuu; run; /* 性別ごとに(方法1) */ title '*** 性別ごとに平均値(方法1) ***'; : 出力に説明を追記する proc means data=gakusei; : 平均を算出 where sex="M"; : 男について計算 var shintyou taijyuu; run; proc means data=gakusei; : 平均を算出 where sex="F"; : 女について計算 var shintyou taijyuu; run; /* 性別ごとに(方法2) */ title '*** 性別ごとに平均値(方法2) ***'; : 出力に説明を追記する proc sort data=gakusei; : 並べ替え(ソート) by sex; : 性別ごとに run; proc means data=gakusei; : 平均の計算 var shintyou taijyuu; : 身長と体重について by sex; : 性別ごとに run; ods listing; : グラフをキャラクタープロットで出力する場合 ods graphics off; : proc univariate data=gakusei plot; : 基礎統計量の計算 var shintyou taijyuu; : 身長と体重について by sex; : 性別ごとに run; /* 性別ごとにヒストグラム(方法1) */ title ' *** 性別ごとにヒストグラム(方法1) ***'; proc chart data=gakusei; : ヒストグラム hbar shintyou taijyuu; : 指定した変量の水平棒グラフを表示 by sex; run; /* 性別ごとにヒストグラム(方法2) */ title '*** 性別ごとにヒストグラム(方法2) ***'; proc chart data=gakusei; : ヒストグラム hbar shintyou taijyuu/group=sex; : 性別ごとに併置して run;
*** データ全体を対象に *** Sunday, January 10, 2021 06:46:53 AM 2 The FREQ Procedure Cumulative Cumulative sex Frequency Percent Frequency Percent -------------------------------------------------------- F 124 33.51 124 33.51 M 246 66.49 370 100.00 Frequency Missing = 124 *** データ全体を対象に *** Sunday, January 10, 2021 06:46:53 AM 3 The MEANS Procedure Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 476 168.6441176 7.9627466 145.0000000 187.0000000 taijyuu 439 59.5487472 9.4619301 35.0000000 100.0000000 -------------------------------------------------------------------------- <<< 中略 >>> *** 性別ごとに平均値(方法1) *** 14 Sunday, January 10, 2021 06:46:53 AM The MEANS Procedure Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 242 172.1876033 5.3909417 156.0000000 186.0000000 taijyuu 242 62.2388430 7.9277377 46.0000000 100.0000000 -------------------------------------------------------------------------- *** 性別ごとに平均値(方法1) *** 15 Sunday, January 10, 2021 06:46:53 AM The MEANS Procedure Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 117 159.0914530 5.3492116 145.0000000 171.0000000 taijyuu 83 48.6987952 4.7229975 35.0000000 60.0000000 -------------------------------------------------------------------------- *** 性別ごとに平均値(方法2) *** 16 Sunday, January 10, 2021 06:46:53 AM sex=' ' The MEANS Procedure Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 117 170.8675214 6.8861659 151.0000000 187.0000000 taijyuu 114 61.7377193 9.4864448 41.0000000 98.0000000 -------------------------------------------------------------------------- sex=F Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 117 159.0914530 5.3492116 145.0000000 171.0000000 taijyuu 83 48.6987952 4.7229975 35.0000000 60.0000000 -------------------------------------------------------------------------- sex=M The MEANS Procedure Variable N Mean Std Dev Minimum Maximum -------------------------------------------------------------------------- shintyou 242 172.1876033 5.3909417 156.0000000 186.0000000 taijyuu 242 62.2388430 7.9277377 46.0000000 100.0000000 -------------------------------------------------------------------------- <<< 中略 >>> *** 性別ごとに平均値(方法2) *** 54 Sunday, January 10, 2021 06:46:54 AM The UNIVARIATE Procedure Variable: shintyou Schematic Plots | 190 + | | | | 0 | | | 180 + | | | | | | +-----+ +-----+ | | | *--+--* 170 + *--+--* | +-----+ | | | | | | +-----+ | | | | +-----+ | 160 + | *--+--* | | | | | 0 | | +-----+ 0 | | 150 + 0 | | | | 0 | 140 + ------------+-----------+-----------+----------- sex F M <<< 中略 >>> *** 性別ごとにヒストグラム(方法1) *** 57 Sunday, January 10, 2021 06:46:54 AM sex=' ' shintyou Cum. Cum. Midpoint Freq Freq Percent Percent | 152.5 |* 1 1 0.85 0.85 | 157.5 |***** 5 6 4.27 5.13 | 162.5 |**************** 16 22 13.68 18.80 | 167.5 |**************************** 28 50 23.93 42.74 | 172.5 |************************** 26 76 22.22 64.96 | 177.5 |**************************** 28 104 23.93 88.89 | 182.5 |*********** 11 115 9.40 98.29 | 187.5 |** 2 117 1.71 100.00 | -----+----+----+----+----+--- 5 10 15 20 25 Frequency <<< 中略 >>> *** 性別ごとにヒストグラム(方法1) *** 59 Sunday, January 10, 2021 06:46:54 AM sex=F shintyou Cum. Cum. Midpoint Freq Freq Percent Percent | 144 |* 1 1 0.85 0.85 147 |*** 3 4 2.56 3.42 150 |***** 5 9 4.27 7.69 153 |************** 14 23 11.97 19.66 156 |********************* 21 44 17.95 37.61 159 |*************************** 27 71 23.08 60.68 162 |******************** 20 91 17.09 77.78 165 |****************** 18 109 15.38 93.16 168 |***** 5 114 4.27 97.44 171 |*** 3 117 2.56 100.00 | -----+----+----+----+----+-- 5 10 15 20 25 Frequency <<< 中略 >>> *** 性別ごとにヒストグラム(方法1) *** 61 Sunday, January 10, 2021 06:46:54 AM sex=M shintyou Cum. Cum. Midpoint Freq Freq Percent Percent | 156 |* 2 2 0.83 0.83 159 |*** 5 7 2.07 2.89 162 |**** 8 15 3.31 6.20 165 |******* 13 28 5.37 11.57 168 |******************** 39 67 16.12 27.69 171 |******************************** 64 131 26.45 54.13 174 |************************** 51 182 21.07 75.21 177 |************** 28 210 11.57 86.78 180 |*********** 21 231 8.68 95.45 183 |**** 8 239 3.31 98.76 186 |** 3 242 1.24 100.00 | -----+----+----+----+----+----+-- 10 20 30 40 50 60 Frequency <<< 中略 >>> *** 性別ごとにヒストグラム(方法2) *** 63 Sunday, January 10, 2021 06:46:54 AM sex shintyou Cum. Cum. Midpoint Freq Freq Percent Percent | 146 | 0 0 0.00 0.00 150 | 1 1 0.21 0.21 154 |* 2 3 0.42 0.63 158 |* 3 6 0.63 1.26 162 |**** 11 17 2.31 3.57 166 |********* 22 39 4.62 8.19 170 |******** 21 60 4.41 12.61 174 |*********** 28 88 5.88 18.49 178 |****** 16 104 3.36 21.85 182 |**** 11 115 2.31 24.16 186 |* 2 117 0.42 24.58 | F 146 |* 2 119 0.42 25.00 150 |*** 8 127 1.68 26.68 154 |******* 17 144 3.57 30.25 158 |************ 31 175 6.51 36.76 162 |************* 33 208 6.93 43.70 166 |********* 22 230 4.62 48.32 170 |** 4 234 0.84 49.16 174 | 0 234 0.00 49.16 178 | 0 234 0.00 49.16 182 | 0 234 0.00 49.16 186 | 0 234 0.00 49.16 | M 146 | 0 234 0.00 49.16 150 | 0 234 0.00 49.16 154 | 0 234 0.00 49.16 158 |* 2 236 0.42 49.58 162 |***** 13 249 2.73 52.31 166 |********** 26 275 5.46 57.77 170 |**************************** 70 345 14.71 72.48 174 |**************************** 71 416 14.92 87.39 178 |************** 36 452 7.56 94.96 182 |******** 19 471 3.99 98.95 186 |** 5 476 1.05 100.00 | ----+---+---+---+---+---+---+ 10 20 30 40 50 60 70 Frequency <<< 後略 >>>
/* Lesson 12-02 */ /* File Name = les1202.sas 01/12/21 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'Kougi19/les1202-Results.txt' new; data gakusei; infile 'StatM20/StudAll20e.csv' firstobs=8 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku : $10. kodukai carryer $ tsuuwa; proc format; value cl_shin 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 cl_shin.; : 連続変量をグループ化することの指定 run; :
Sunday, January 10, 2021 06:53:05 AM 96 ----------------------------------------------------------------------- | | sex | | |---------------------------------------------------| | | F | M | | |-------------------------+-------------------------| | | jitaku | jitaku | | |-------------------------+-------------------------| | | 下宿生 | 自宅生 | 下宿生 | 自宅生 | |-----------------+------------+------------+------------+------------| |kodukai |N | 34.00| 68.00| 82.00| 126.00| | |--------+------------+------------+------------+------------| | |Mean | 77647.06| 35110.29| 86256.10| 25777.78| | |--------+------------+------------+------------+------------| | |Std | 58390.47| 31307.91| 59470.88| 32858.21| ----------------------------------------------------------------------- Sunday, January 10, 2021 06:53:05 AM 97 ----------------------------------------------------------------------- | | shintyou | | |---------------------------------------------------| | | -149 | 150-159 | 160-169 | | |------------+-------------------------+------------| | | sex | sex | sex | | |------------+-------------------------+------------| | | F | F | M | F | |-----------------+------------+------------+------------+------------| |taijyuu |N | 5.00| 40.00| 2.00| 38.00| | |--------+------------+------------+------------+------------| | |Mean | 41.80| 47.31| 54.50| 51.07| | |--------+------------+------------+------------+------------| | |Std | 2.59| 4.61| 9.19| 3.47| ----------------------------------------------------------------------- (Continued) Sunday, January 10, 2021 06:53:05 AM 98 ----------------------------------------------------------------------- | | shintyou | | |---------------------------------------------------| | | 160-169 | 170-179 | 180- | | |------------+-------------------------+------------| | | sex | sex | sex | | |------------+-------------------------+------------| | | M | F | M | M | |-----------------+------------+------------+------------+------------| |taijyuu |N | 65.00| 0.00| 151.00| 24.00| | |--------+------------+------------+------------+------------| | |Mean | 58.50| .| 63.10| 67.56| | |--------+------------+------------+------------+------------| | |Std | 7.35| .| 7.54| 7.38| -----------------------------------------------------------------------
if sex=" " or shintyou="." or taijyuu="." then delete; : 欠損値を含んだデータは除外
if taijyuu>85 then delete; : 体重が85を超えるデータは除外
if kyoui<60 then delete; : 胸囲が60未満のデータは除外
[例1] 目的のサンプルだけを抽出する : 条件を書き並べる
[例2] 新しい変量を定義する : 新しい変量を左辺に書く
[例3] 変量の値を割り当てなおす : 新しい値を右辺に書く
data gakusei; infile 'Kougi20/daigaku08.csv' firstobs=2 dlm=',' dsd missover encoding=sjis termstr=crlf; input id $ sex $ kesseki $ univ $ koku $ suu1 $ suu2 $ tireki $ koumin $ rika $; if sex^='M' then delete; /* 男(male)のみを対象とする */ if kesseki^='0' then delete; /* 出席者のみを対象とする */ area="不明"; if univ="早稲田大学" then area="東日本"; if univ="慶応大学" then area="東日本"; if univ="関西大学" then area="西日本"; if univ="同志社大学" then area="西日本"; if tireki="世界史-0" then tireki="世界史"; if tireki="世界史-2" then tireki="世界史"; if tireki="日本史-2" then tireki="日本史"; if tireki="日本史-3" then tireki="日本史"; ...
[例4] 複数の処理をさせたい場合 : do 〜 end で囲む
if tireki="世界史-0" then do; tireki="世界史"; koumin=.; /* ドットは欠損値を示す */ end; ...
/* Lesson 12-04 */ /* File Name = les1204.sas 01/12/21 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'StatM20/les1204-Results.txt' new; data gakusei; infile 'StatM20/StudAll20e.csv' firstobs=8 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku : $10. kodukai carryer $ tsuuwa; if sex=" " or shintyou="." or taijyuu="." then delete; proc print data=gakusei(obs=5); run; proc sort data=gakusei; by sex; run; proc univariate data=gakusei plot; : 分布が正規分布とみなせるか var shintyou taijyuu kyoui kodukai; : 各変量ごとに by sex; : 性別ごとに計算 run; proc ttest data=gakusei; : 平均値の差の検定 class sex; : 性別の違いによる比較 var shintyou taijyuu kyoui kodukai; : 各変量ごとに run;
Sunday, January 10, 2021 06:58:31 AM 173 The TTEST Procedure Variable: shintyou sex Method N Mean Std Dev Std Err F 83 158.5 5.4081 0.5936 M 242 172.2 5.3909 0.3465 Diff (1-2) Pooled -13.6768 5.3953 0.6863 Diff (1-2) Satterthwaite -13.6768 0.6874 sex Method Minimum Maximum F 145.0 168.0 M 156.0 186.0 Diff (1-2) Pooled Diff (1-2) Satterthwaite sex Method Mean 95% CL Mean Std Dev F 158.5 157.3 159.7 5.4081 M 172.2 171.5 172.9 5.3909 Diff (1-2) Pooled -13.6768 -15.0269 -12.3266 5.3953 Diff (1-2) Satterthwaite -13.6768 -15.0356 -12.3180 sex Method 95% CL Std Dev F 4.6920 6.3841 M 4.9496 5.9193 Diff (1-2) Pooled 5.0094 5.8461 Diff (1-2) Satterthwaite Method Variances DF t Value Pr > |t| Pooled Equal 323 -19.93 <.0001 Satterthwaite Unequal 141.81 -19.90 <.0001 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 82 241 1.01 0.9484 Sunday, January 10, 2021 06:58:32 AM 175 The TTEST Procedure Variable: taijyuu sex Method N Mean Std Dev Std Err F 83 48.6988 4.7230 0.5184 M 242 62.2388 7.9277 0.5096 Diff (1-2) Pooled -13.5400 7.2496 0.9222 Diff (1-2) Satterthwaite -13.5400 0.7270 sex Method Minimum Maximum F 35.0000 60.0000 M 46.0000 100.0 Diff (1-2) Pooled Diff (1-2) Satterthwaite sex Method Mean 95% CL Mean Std Dev F 48.6988 47.6675 49.7301 4.7230 M 62.2388 61.2350 63.2427 7.9277 Diff (1-2) Pooled -13.5400 -15.3543 -11.7258 7.2496 Diff (1-2) Satterthwaite -13.5400 -14.9721 -12.1080 sex Method 95% CL Std Dev F 4.0977 5.5753 M 7.2788 8.7048 Diff (1-2) Pooled 6.7311 7.8553 Diff (1-2) Satterthwaite Method Variances DF t Value Pr > |t| Pooled Equal 323 -14.68 <.0001 Satterthwaite Unequal 240.6 -18.63 <.0001 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 241 82 2.82 <.0001 Sunday, January 10, 2021 06:58:32 AM 177 The TTEST Procedure Variable: kyoui sex Method N Mean Std Dev Std Err F 43 83.0000 3.9036 0.5953 M 71 88.0986 9.6853 1.1494 Diff (1-2) Pooled -5.0986 8.0213 1.5500 Diff (1-2) Satterthwaite -5.0986 1.2944 sex Method Minimum Maximum F 70.0000 90.0000 M 46.0000 112.0 Diff (1-2) Pooled Diff (1-2) Satterthwaite sex Method Mean 95% CL Mean Std Dev F 83.0000 81.7986 84.2014 3.9036 M 88.0986 85.8061 90.3911 9.6853 Diff (1-2) Pooled -5.0986 -8.1698 -2.0274 8.0213 Diff (1-2) Satterthwaite -5.0986 -7.6665 -2.5306 sex Method 95% CL Std Dev F 3.2187 4.9615 M 8.3128 11.6049 Diff (1-2) Pooled 7.0944 9.2292 Diff (1-2) Satterthwaite Method Variances DF t Value Pr > |t| Pooled Equal 112 -3.29 0.0013 Satterthwaite Unequal 100.53 -3.94 0.0002 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 70 42 6.16 <.0001 Sunday, January 10, 2021 06:58:33 AM 179 The TTEST Procedure Variable: kodukai sex Method N Mean Std Dev Std Err F 78 49314.1 48483.6 5489.7 M 229 48620.1 52676.9 3481.0 Diff (1-2) Pooled 694.0 51650.4 6771.4 Diff (1-2) Satterthwaite 694.0 6500.3 sex Method Minimum Maximum F 0 300000 M 0 350000 Diff (1-2) Pooled Diff (1-2) Satterthwaite sex Method Mean 95% CL Mean Std Dev F 49314.1 38382.7 60245.5 48483.6 M 48620.1 41761.1 55479.1 52676.9 Diff (1-2) Pooled 694.0 -12630.5 14018.6 51650.4 Diff (1-2) Satterthwaite 694.0 -12154.7 13542.7 sex Method 95% CL Std Dev F 41887.9 57564.0 M 48253.8 57999.7 Diff (1-2) Pooled 47856.7 56102.5 Diff (1-2) Satterthwaite Method Variances DF t Value Pr > |t| Pooled Equal 305 0.10 0.9184 Satterthwaite Unequal 143.53 0.11 0.9151 Equality of Variances Method Num DF Den DF F Value Pr > F Folded F 228 77 1.18 0.3980
/* Lesson 12-05 */ /* File Name = les1205.sas 01/12/21 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'StatM20/les1205-Results.txt' new; data gakusei; infile 'StatM20/StudAll20e.csv' firstobs=8 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku : $10. kodukai carryer $ tsuuwa; if sex=" " or shintyou="." or taijyuu="." then delete; proc print data=gakusei(obs=5); run; proc npar1way data=gakusei wilcoxon; : Wilcoxon 検定 class sex; : 分類したい特性変数の指定 var shintyou taijyuu kyoui kodukai; : 比較したい変量名 run;
Sunday, January 10, 2021 07:01:13 AM 182 The NPAR1WAY Procedure Wilcoxon Scores (Rank Sums) for Variable shintyou Classified by Variable sex Sum of Expected Std Dev Mean sex N Scores Under H0 Under H0 Score F 83 4124.0 13529.0 738.142405 49.686747 M 242 48851.0 39446.0 738.142405 201.863636 Average scores were used for ties. Wilcoxon Two-Sample Test t Approximation Statistic Z Pr < Z Pr > |Z| Pr < Z Pr > |Z| 4124.000 -12.7408 <.0001 <.0001 <.0001 <.0001 Z includes a continuity correction of 0.5. Sunday, January 10, 2021 07:01:13 AM 183 The NPAR1WAY Procedure Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 162.3444 1 <.0001 Sunday, January 10, 2021 07:01:14 AM 184 The NPAR1WAY Procedure Wilcoxon Scores (Rank Sums) for Variable taijyuu Classified by Variable sex Sum of Expected Std Dev Mean sex N Scores Under H0 Under H0 Score F 83 4424.0 13529.0 738.002845 53.301205 M 242 48551.0 39446.0 738.002845 200.623967 Average scores were used for ties. Wilcoxon Two-Sample Test t Approximation Statistic Z Pr < Z Pr > |Z| Pr < Z Pr > |Z| 4424.000 -12.3367 <.0001 <.0001 <.0001 <.0001 Z includes a continuity correction of 0.5. Sunday, January 10, 2021 07:01:14 AM 185 The NPAR1WAY Procedure Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 152.2102 1 <.0001 Sunday, January 10, 2021 07:01:14 AM 186 The NPAR1WAY Procedure Wilcoxon Scores (Rank Sums) for Variable kyoui Classified by Variable sex Sum of Expected Std Dev Mean sex N Scores Under H0 Under H0 Score F 43 1648.50 2472.50 170.162136 38.337209 M 71 4906.50 4082.50 170.162136 69.105634 Average scores were used for ties. Wilcoxon Two-Sample Test t Approximation Statistic Z Pr < Z Pr > |Z| Pr < Z Pr > |Z| 1648.500 -4.8395 <.0001 <.0001 <.0001 <.0001 Z includes a continuity correction of 0.5. Sunday, January 10, 2021 07:01:14 AM 187 The NPAR1WAY Procedure Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 23.4492 1 <.0001 Sunday, January 10, 2021 07:01:14 AM 188 The NPAR1WAY Procedure Wilcoxon Scores (Rank Sums) for Variable kodukai Classified by Variable sex Sum of Expected Std Dev Mean sex N Scores Under H0 Under H0 Score F 78 12660.50 12012.0 673.661387 162.314103 M 229 34617.50 35266.0 673.661387 151.168122 Average scores were used for ties. Wilcoxon Two-Sample Test t Approximation Statistic Z Pr > Z Pr > |Z| Pr > Z Pr > |Z| 12660.50 0.9619 0.1680 0.3361 0.1684 0.3369 Z includes a continuity correction of 0.5. Sunday, January 10, 2021 07:01:14 AM 189 The NPAR1WAY Procedure Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 0.9267 1 0.3357