SAS Codes:
/*將資料讀進SAS*/
data Color;
/*$代表變數為文字 @@為自由符號使不同的觀測值可以放在同一行,如範例*/
/*$代表變數為文字 @@為自由符號使不同的觀測值可以放在同一行,如範例*/
label Eyes ='Eye Color'
Hair ='Hair Color'
Region='Geographic Region';
datalines;
1 blue
fair 23 1 blue
red 7 1 blue
medium 24
1 blue
dark 11 1 green fair
19 1 green red 7
1 green medium 18 1 green dark
14 1 brown fair 34
1 brown red 5 1
brown medium 41 1 brown dark 40
1 brown black 3 2
blue fair 46 2
blue red 21
2 blue
medium 44 2 blue dark
40 2 blue black
6
2 green fair 50 2
green red 31 2 green medium 37
2 green dark 23 2
brown fair 56 2 brown red
42
2 brown medium 53 2 brown dark
54 2 brown black 13
/*
若無加權數(weight)跑Eyes與Eyes*Hair的列聯表
加入chisq語法可以做卡方檢定
此例子的虛無假設(H0)為不同顏色頭髮的比例相同<=>P1=P2=P3
*/
若無加權數(weight)跑Eyes與Eyes*Hair的列聯表
加入chisq語法可以做卡方檢定
此例子的虛無假設(H0)為不同顏色頭髮的比例相同<=>P1=P2=P3
*/
proc freq data=Color;
tables Eyes
Eyes*Hair / out=FreqCount outexpect sparse chisq ;
title 'Eye
and Hair Color of European Children without weight' ;
run;
/*加權數(weight)跑Eyes與Eyes*Hair的列聯表*/
proc freq data=Color;
tables Eyes
Eyes*Hair / out=FreqCount outexpect sparse chisq ;
weight Count;
title 'Eye
and Hair Color of European Children with weight';
run;
proc print data=FreqCount
noobs;
title2 'Output Data Set from PROC FREQ';
run;
資料來源:
SAS Help and documentation Example 36.1 Output Data Set of Frequencies
沒有留言:
張貼留言