简体   繁体   中英

How to create 2x2 table in sas for fisher exact test

I just performed the fisher test in R and in Excel on a 2x2 table with the contents 1 6 and 7 2. I can't manage to do this in sas.

data my_table;
input  var1 var2 @@;
datalines;
1 6 7 2
;

proc freq data=my_table;
tables var1*var2 / fisher;
run;

The test somehow ignores that the table consists of the 4 variables but when I print the table it looks fine. In the test the contents of the table are 0, 1, 1, 0. I guess I need to change something when creating the data but what?

You do NOT have two variables that each have two categories.

Read the data in this way instead.

data have ;
  do var1=1,2 ; do var2=1,2;
    input count @@;
    output;
  end; end;
datalines;
1 6 7 2
;

Now VAR1 and VAR2 both have two possible values and COUNT has the number of cases for the particular combination. Use the WEIGHT statement to tell PROC FREQ to use COUNT as the number of cases.

proc freq data=have ;
  weight count ;
  tables var1*var2 / fisher ;
run;

在此处输入图像描述 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM