Programming the statistical procedures from SAS

IF-THEN statement for chi square/fisher's exact test

Reply
N/A
Posts: 0

IF-THEN statement for chi square/fisher's exact test

Hi

Is it possible to use an IF-THEN statement for chi square tests?
For example, if statistical significance is determined at p < 0.05, then is there a way to sieve out those that have p values less than 0.05 and classify them as significant?
Valued Guide
Valued Guide
Posts: 684

Re: IF-THEN statement for chi square/fisher's exact test

I assume you have a chi-square test for each of several groups, and that the groups are all stacked in the same data file. The specific approach will depend on which PROC you are using (FREQ, etc.). You should first be able to get the displayed output for each group (using by statement) for the desired PROC. The general instruction is to find the ODS output table name for the specific procedure that contains the test statistics, P values, etc. Store this table as a file, as explained for use of ODS, in general. Then, perform an IF-THEN operation on this file, and then print this new file.
Can't give more specific instructions until you first get the procedure running.
Valued Guide
Valued Guide
Posts: 684

Re: IF-THEN statement for chi square/fisher's exact test

As a follow-up to my previous email, here is a quick way to do what I think you want. I took a sas program from a previous post I made (involving PROC FREQ), and changed the values for the second group. The program does the FIsher's exact test and stores the results in file fe. See the printout of the full file. Then I eliminated the extra lines and dropped the group that had P > 0.05, leaving one line in the file. See the printout for file fe2.

DATA a; *---from a previous post, but with numbers in group 2 changed;
INPUT group FLOWERS $ COLOURS $ COUNT ;
DATALINES;
1 A I 18
1 A II 15
1 A III 12
1 B I 44
1 B II 43
1 B III 34
1 C I 34
1 C II 31
1 C III 37
2 A I 5
2 A II 5
2 A III 12
2 B I 6
2 B II 47
2 B III 17
2 C I 10
2 C II 10
2 C III 8
;
proc print data=a;
RUN;
PROC FREQ data=a;
ods output fishersexact=fe;
by group;
WEIGHT COUNT;
TABLES flowers*colours;
EXACT FISHER;
RUN;
proc print data=fe; *---All results for Fisher;
run;

data fe2; set fe;
if (Name1 eq 'XP2_FISH');
if (cValue1 le 0.05);
proc print data=fe2; *---Show group with significant result (P < 0.05);
run;
N/A
Posts: 0

Re: IF-THEN statement for chi square/fisher's exact test

thank you!
Ask a Question
Discussion stats
  • 3 replies
  • 152 views
  • 0 likes
  • 2 in conversation