/* Lesson 12-01 */
/* File Name = les1201.sas 01/07/20 */
options nocenter linesize=78 pagesize=30;
options locale='en_US';
/* options locale='ja_JP'; */
proc printto print = 'Kougi19/les1201-Results.txt' new;
data gakusei;
infile 'Kougi19/all19b.csv'
firstobs=2 dlm=',' dsd missover
encoding=sjis termstr=crlf;
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; :
Monday, January 6, 2020 10:27:41 PM 6
-----------------------------------------------------------------------
| | sex |
| |---------------------------------------------------|
| | F | M |
| |-------------------------+-------------------------|
| | jitaku | jitaku |
| |-------------------------+-------------------------|
| | G | J | G | J |
|-----------------+------------+------------+------------+------------|
|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|
-----------------------------------------------------------------------
Monday, January 6, 2020 10:27:41 PM 7
-----------------------------------------------------------------------
| | 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)
Monday, January 6, 2020 10:27:41 PM 8
-----------------------------------------------------------------------
| | 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; : 欠損値を含んだデータは除外
[例1] 目的のサンプルだけを抽出する : 条件を書き並べる
[例2] 新しい変量を定義する : 新しい変量を左辺に書く
[例3] 変量の値を割り当てなおす : 新しい値を右辺に書く
data gakusei; infile 'Kougi19/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-03 */ /* File Name = les1203.sas 01/07/20 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'Kougi19/les1203-Results.txt' new; data gakusei; infile 'Kougi19/all19b.csv' firstobs=2 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku $ 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;
Monday, January 6, 2020 10:31:04 PM 122 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 Monday, January 6, 2020 10:31:05 PM 124 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 Monday, January 6, 2020 10:31:05 PM 126 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 Monday, January 6, 2020 10:31:06 PM 128 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-04 */ /* File Name = les1204.sas 01/07/20 */ options nocenter linesize=78 pagesize=30; options locale='en_US'; /* options locale='ja_JP'; */ proc printto print = 'Kougi19/les1204-Results.txt' new; data gakusei; infile 'Kougi19/all19b.csv' firstobs=2 dlm=',' dsd missover encoding=sjis termstr=crlf; input sex $ shintyou taijyuu kyoui jitaku $ 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;
Monday, January 6, 2020 10:31:37 PM 131 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. Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 162.3444 1 <.0001 Monday, January 6, 2020 10:31:37 PM 133 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. Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 152.2102 1 <.0001 Monday, January 6, 2020 10:31:38 PM 135 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. Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 23.4492 1 <.0001 Monday, January 6, 2020 10:31:38 PM 137 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. Kruskal-Wallis Test Chi-Square DF Pr > ChiSq 0.9267 1 0.3357