目前僅能執行獨立性卡方檢定及Fisher's exact檢定,
並且關閉一些結果表的顯示,如要呈現其他項目 如表格內百分比,
請於執行前在程式尾端自行修改
DM LOG 'CLEAR';
DM OUTPUT 'CLEAR';
Data Welcom;
Window Welcom Color=white Columns=100 Rows=100
#5 @50 "-------------歡迎使用本SAS程式Window視窗版--------------" color=red
#7 @50 "----------此程式使用於卡方檢定(樣本獨立性檢定)----------" color=red
#9 @50 "------------------------列聯表分析----------------------" color=blue
#14 @50 "請按Enter進入欄位設定及檢定視窗"
#18 @50 "註:本分析程式僅呈現列聯表及進行卡方統計處理,如要顯示其他數據如期望值、百分比等," color=blue
#19 @50 " 請執行前自行於本程式最末端修改,尚不包含適合度檢定其他分佈期望值" color=blue
;
Display Welcom ;
stop ;
run;
%let x=2;
%let y=2;
Data SelectTable;
retain x 2 y 2;
Window Select Color=white Columns=100 Rows=100
#1 @58 '--------------列聯表分析--------------' color=red
#3 @58 '請輸入為X乘Y列聯表' color=red
#5 @52 'X*Y=' color=blue
#5 @63 '*' color=red
#5 @58 x 5. color=red a=underline auto=yes required=yes
#5 @64 y 5. color=red a=underline auto=yes required=yes
#13 @50 "本列聯表預設值為2X2,如欲使用其他列聯,請將數值刪除再改為自己需要的"
#14 @50 "並在各欄位數值鍵入完或最右下欄位鍵入完,請按鍵盤Enter鍵,以方便跳位及資料進入SAS程式內"
#15 @50 "當各數值鍵入完成後請至上方Command===>處鍵入關鍵字: end"
;
Display Select ;
run;
proc sql ;
select x , y into :x ,:y
from SelectTable (obs=1);
run;
quit;
%macro Tabletrans;
Data Tablewindow;
retain
%do ssy= 1 %to &y;
%do ssx = 1 %to &x ;
x&ssx.y&ssy 0
%end;
%end;
;
Window Table Color=white Columns=100 Rows=100
#3 @58 '變相X' color=red
%do xn=1 %to &x;
%let xsit=%eval(43+10*&xn);
#4 @&xsit "X=&xn" color=blue
%end;
#7 @43 '變' color=red
#8 @43 '項' color=red
#9 @43 'Y' color=red
%do yn=1 %to &y;
%let ysit=%eval(4+3*&yn);
#&ysit @46 "Y=&yn" color=blue
%end;
%let vlbar=%eval(5+3*&y);
%let xbar="----------" ;
#5 @50
%do b=1 %to &x ;
&xbar
%end;
%let xbar="----------" ;
#&vlbar @50
%do b=1 %to &x ;
&xbar
%end;
%do vb=1 %to &y;
%let vspec=%eval(5+3*(&vb-1));
%Let xcbar='|---------' ;
#&vspec @50
%do b=1 %to &x ;
&xcbar
%end;
%end;
%do a= 1 %to &y ;
%let vca1=%eval(6+3*(&a-1));
%let vca2=%eval(7+3*(&a-1));
%let vca3=%eval(8+3*(&a-1));
%let h=%eval(&x+1);
%do hbarn= 1 %to &h ;
%let hbar=%eval(40+10*&hbarn) ;
#&vca1 @&hbar '|'
#&vca2 @&hbar '|'
%end;
#&vca3 @&hbar '|'
%end;
%do yyy= 1 %to &y;
%let varys=%eval(3+3*&yyy);
%do xxx = 1 %to &x ;
%let varxspe=%eval(41+10*&xxx);
#&varys @&varxspe x&xxx.y&yyy 5. color=red a=underline auto=yes required=yes
%end;
%end;
%let footnote1=%eval(&vlbar+5);
%let footnote2=%eval(&vlbar+6);
#&footnote1 @50 "請將預設值先行刪除,並在各欄位數值鍵入完或最右下欄位,按Enter以方便跳位"
#&footnote2 @50 "鍵入完成後請至上方Command===>處鍵入 : end"
;
Display Table;
run;
%mend;
%Tabletrans;
proc transpose data=Tablewindow prefix=weight name=local out=weightnum;
run;
data tablecut;
set weightnum;
xx=scan(local,1 , 'y');
xxx=scan(xx,1,'x');
yyy=scan(local,2 , 'y');
label xxx='變項X' yyy='變項Y';
run;
proc freq data= tablecut;
table yyy*xxx /chisq norow nocol nopercent exact;
weight weight1;
run;