sas實習111229
TRANSCRIPT
PROC FREQ Statement
PROC FREQ <options> ;
BY Statement
EXACT Statement
OUTPUT Statement
TABLES Statement
TEST Statement
WEIGHT Statement
PROC FREQ <options> ;
TABLES requests </ options> ;
Requests 對應的output
tables A*(B C); A*B、A*C
tables (A B)*(C D); A*C、B*C、A*D、B*D
tables (A B C)*D; A*D、B*D、C*D
tables A – – C; A、B、C
tables (A – – C)*D; A*D、B*D、C*D
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 512
5. 0 Y 54
6. 1 N 227
7. 1 Y 37
8. 2 N 59
9. 2 Y 15
10. 3-4 N 18
11. 3-4 Y 12
12. ;
13. proc freq data=a;
14. weight count;
15. tables childabuse*adultabuse;
16. run;
CODE
Number of
child abuse
categories
Abused as adultTotal
No Yes
0 512 54 566
1 227 37 264
2 59 15 74
3~4 18 12 30
Total 816 118 934
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 512
5. 0 Y 54
6. 1 N 227
7. 1 Y 37
8. 2 N 59
9. 2 Y 15
10. 3-4 N 18
11. 3-4 Y 12
12. ;
13. proc freq data=a;
14. weight count;
15. tables childabuse*adultabuse;
16. run;
CODE
OUTPUT
Number of
child
abuse
categories
Abused as
adultTotal
No Yes
0 512 54 566
1 227 37 264
2 59 15 74
3~4 18 12 30
Total 816 118 934
OUTPUT
Without
options:
頻率
百分比
列百分比
欄百分比
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 512
5. 0 Y 54
6. 1 N 227
7. 1 Y 37
8. 2 N 59
9. 2 Y 15
10. 3-4 N 18
11. 3-4 Y 12
12. ;
13. proc freq data=a;
14. weight count;
15. tables childabuse*adultabuse/expected;
16. run;
CODE
OUTPUT
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 512
5. …
6. 3-4 Y 12
7. ;
8. proc freq data=a;
9. weight count;
10. tables childabuse*adultabuse/chisq;
11. run;
CODE卡方檢定
OUTPUT
OUTPUT
G2
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 3
5. 0 Y 3
6. 1 N 1
7. 1 Y 1
8. 2 N 1
9. 2 Y 0
10. 3-4 N 0
11. 3-4 Y 1
12. ;
13. proc freq data=a;
14. weight count;
15. tables childabuse*adultabuse/fisher;
16. run;
CODE
OUTPUT
N<20即有此警告
Goodness of fit
適合度檢定
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N512
5. …
6. 3-4 Y 12
7. ;
8. proc freq data=a;
9. weight count;
10. tables childabuse/chisq testp=(20 30 30 20);
11. run;
CODENumber of
child
abuse
categories
Abused as
adultTotal
No Yes
0 512 54 566
1 227 37 264
2 59 15 74
3~4 18 12 30
Total 816 118 934
OUTPUT
TESTFSpecifies expected frequencies for one-
way chi-square test
TESTPSpecifies expected proportions for one-
way chi-square test
1. data a;
2. input J1 $ J2 $ count;
3. datalines;
4. N N 512
5. N Y 54
6. Y Y 227
7. Y N 37
8. ;
9. proc freq data=a;
10. weight count;
11. tables J1*J2/agree;
12. run;
CODE
Kappa (κ): A measure of
agreement
OUTPUT
BINOMIAL <(binomial-options)>
1. data a;
2. input childabuse $ adultabuse $ count;
3. datalines;
4. 0 N 512
5. …
6. 3-4 Y 20
7. ;
8. proc freq data=a;
9. weight count;
10. tables adultabuse/binomial;
11. run;
CODE
OUTPUT