| Date: | Tue, 22 Apr 2003 18:14:47 -0700 |
| Reply-To: | Bill Anderson <wnilesanderson@COX.NET> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Bill Anderson <wnilesanderson@COX.NET> |
| Subject: | Re: Chi-square and Fisher Exact Test |
|
| Content-Type: | text/plain; charset="iso-8859-1" |
Don,
The code below is lifted from a working program, although I have taken a bit
of proprietary stuff out of the variable names. The code actually grabs the
counts as well as the Fisher p-value. The whole thing was included in a big
macro that analyzed a bunch of 2 by 2 tables, and I have not taken the time
to make the code standalone. But I think you can figure out how to adopt
the code to your purposes.
I am sure you will get more elegant code from some of the list regulars, but
in the meantime this will work.
2 WARNINGS:
The counts are always there, unless the data set is empty. But Fisher's
exact test might not always be meaningful, so it is worth testing if it was
created.
In any event, you should delete the output data sets after using them, just
to make sure you don't use the wrong set next time around.
Bill Anderson
title&titleno1 'Comparison of Test vs. Control';
ods output FishersExact = inttest CrossTabFreqs = CrossTabFreqs;
proc freq data = &inset;
tables &var*&groupvar/chisq &exact;
run;
%armcounts(crosstabfreqs)
/* did we get a p-value? */
%let fisherid = %sysfunc(open(inttest, i));
%let rc = %sysfunc(close(&fisherid));
%if &fisherid ^= 0 %then %do;
%onefvalue(inttest)
data discreterow; merge crosstabfreqs inttest; run; /* one observation each
*/
%end;
%else %do; data discreterow; set crosstabfreqs; %end;
data &countset; set &countset discreterow (in = new);
if new then do; variable = "&var"; varlabel = "&label"; end;
run;
/* play it safe for next time around */
proc datasets nolist; delete inttest CrossTabFreqs discreterow; quit;
%macro armcounts(name);
/* set up for the specific variable values here */
data &name; set &name end = last;
keep control_yes control_no lvas_yes lvas_no;
retain control_yes control_no lvas_yes lvas_no;
if &var = 0 & trialarm = 'Test' then test_no = frequency;
if &var = 1 & trialarm = 'Test' then test_yes = frequency;
if &var = 0 & trialarm = 'Control' then control_no = frequency;
if &var = 1 & trialarm = 'Control' then control_yes = frequency;
if last then output;
run;
%mend;
%macro onefvalue(name);
data &name; set &name; keep nvalue1; rename nvalue1 = &name; if Name1 =
'XP2_FISH'; run;
%mend;
----- Original Message -----
From: "Don Smith" <donsas99@HOTMAIL.COM>
Sent: Monday, April 14, 2003 7:12 PM
Subject: Chi-square and Fisher Exact Test
> Hi Sas-Lers:
>
> I'm using PROC FREQ to do a chi-square test for a 2x2 contingency table.
> Does anyone have a macro (and is willing to share it) that will pick up
the
> appropriate p-value, that is, it pick's up the Fisher Exact Test result,
> whenever, it's appropriate?
>
> Any assitance is greatly appreciated.
>
> Don
>
>
>
> _________________________________________________________________
> Tired of spam? Get advanced junk mail protection with MSN 8.
> http://join.msn.com/?page=features/junkmail
>
|