DATA Step, Macro, Functions and more

Fisher test with Monte Carlo

Reply
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Fisher test with Monte Carlo

Using SAS 9.4

 

Hello,

 

I have formatted a variable race

proc format;

value $Race 'C' = 'Caucasian'

'AA' = 'African American'

other = 'Unknown/Other';

run;

 

and this works for some tests, (eg)

proc freq data = mylib.a (where=(Used_recommendation = 'Yes'));

tables  Race /chisq list missing nocum;

format  Race $Race.;

title Table 1. ‘Demographics’;

run;

 

However my format does not work when I run a fisher exact test with monte carlo estimates (eg)

proc freq data = mylib.a;

tables Used_recommendation*Race;

format Race $Race.;

exact fisher /mc;

run;

 

It comes up with my Caucasian and African American groups but neglects the other/unknown category. Am I doing something wrong? Is their a better way to write my code so that it would work? Thank you

SAS Super FREQ
Posts: 4,239

Re: Fisher test with Monte Carlo

[ Edited ]

Do you use missing values to code the "Other" category, or are the values nonmissing? (Missing values will be ignored, even if they are formatted.)

 

Do you see any warnings in the SAS log? How many observations in the data? Exact tests can be computing intensive, so you might get an error message for huge data sets,

 

Your PROC FREQ statement looks correct. It runs on the following simulated data. I conclude that there is something specific to your data that is causing the issue:

 

data Have;
array RaceCode[3] $2 ("C" "AA" "O");
call streaminit(321);
do i = 1 to 1000;
   k = rand("Table", 0.45, 0.35, 0.2);
   Race = RaceCode[k];
   Used_recommendation = rand("Bernoulli", 0.6*k/4);
   output;
end;
keep i Race Used_recommendation;
run;

proc format;
value $Race 'C' = 'Caucasian'
'AA' = 'African American'
other = 'Unknown/Other';
run;
 
proc freq data = Have;
tables Used_recommendation*Race;
format Race $Race.;
exact fisher /mc;
run;
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: Fisher test with Monte Carlo

I am using 'other'  to code for missing data. Would it be more effective to use '.' to code for the missing data?

SAS Super FREQ
Posts: 4,239

Re: Fisher test with Monte Carlo

Ah! Well that explains it. By default PROC FREQ drops observations that have missing values. You need to tell it that it should consider missing values as a valid category:

 

proc freq data = Have;
   tables Used_recommendation*Race / MISSING; /* <== */
   format Race $Race.;
   exact fisher /mc;
run;
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: Fisher test with Monte Carlo

Is their a way to write that into my sas format code so that I can name the missing values? Thank you

SAS Super FREQ
Posts: 4,239

Re: Fisher test with Monte Carlo

You already have it covered. The missing values will be labeled as 'Unknown/Other', according to your format.

Ask a Question
Discussion stats
  • 5 replies
  • 101 views
  • 0 likes
  • 2 in conversation