I have data formatted as follows:
data have;
input ID DOSENUM TRTN RESULT $ @@;
cards;
1 1 1 Y
1 2 1 N
1 3 1 N
2 1 1 N
2 2 1 N
2 3 1 Y
3 1 1 N
3 2 1 Y
4 1 2 N
4 2 2 N
4 3 2 N
5 1 2 N
5 2 2 Y
6 1 2 N
6 2 2 Y
6 3 2 Y
;
run;
I want to find the p-value of Fisher's exact test comparing TRTN=1 to TRTN=2 for each dose. I am having a bit difficulty conceptualizing what needs to be tabled in PROC FREQ... I was thinking of doing the following, but am unsure if it gives me the p-value I want.
proc freq data= have; by DOSENUM; tables TRTN*RESULT/ fisher; run;
Alternatively, add DOSENUM as a stratification variable to the TABLES statement:
tables DOSENUM*TRTN*RESULT/ fisher;
With that you can use the existing (unsorted) HAVE dataset, omit the BY statement and still obtain the same result: Fisher's exact test applied separately to the three dose groups.
However, from your description ("the p-value") I'm not sure if you want three p-values or rather a single p-value, maybe from an exact test for the common odds ratio, adjusting for DOSENUM, if appropriate for your data. This would be a kind of generalization of Fisher's exact test and could be requested by an EXACT statement (exact comor;).
When you do a BY-group analysis of data, you need to make sure that the data are sorted by the BY-group variable. Before calling PROC FREQ, use the following call to PROC SORT:
proc sort data=have;
by DOSENUM;
run;
Alternatively, add DOSENUM as a stratification variable to the TABLES statement:
tables DOSENUM*TRTN*RESULT/ fisher;
With that you can use the existing (unsorted) HAVE dataset, omit the BY statement and still obtain the same result: Fisher's exact test applied separately to the three dose groups.
However, from your description ("the p-value") I'm not sure if you want three p-values or rather a single p-value, maybe from an exact test for the common odds ratio, adjusting for DOSENUM, if appropriate for your data. This would be a kind of generalization of Fisher's exact test and could be requested by an EXACT statement (exact comor;).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.