Programming the statistical procedures from SAS

repeated chi-square tests

Reply
N/A
Posts: 0

repeated chi-square tests

Hi

neeed some help in this.

I am currently using this program to run the chi sq/fishers exact test:
DATA;
INPUT FLOWERS $ COLOURS $ COUNT @@;
DATALINES;
A I 18 II 15 III 12
B I 44 II 43 III 34
C I 34 II 31 III 37
;
RUN;
PROC FREQ;
WEIGHT COUNT;
TABLES flowers*colours;
EXACT FISHER;
RUN;

However, this is just for an individual observation and I have many rows of data, with each observation tabulated as a 3x3 table. Is there a macro that can run a chisq/fishers exact test for every 3 rows of data?

thanks
Super Contributor
Posts: 281

Re: repeated chi-square tests

You should be able to use a BY statement in PROC FREQ
N/A
Posts: 0

Re: repeated chi-square tests

I tried inserting the BY statement but then the chi square test gets messed up.
Valued Guide
Valued Guide
Posts: 684

Re: repeated chi-square tests

Before dealing with multiple tests, your input data file is not what you think. You are specifying that the first flower type is A and the first colour type is "18", with a count of 12. Because of the @@, the next flower type is "12", the next colour is "B", with a count of "44". And so on. If your really have three flower types (and how many colours?), you should best have three values per record:
Flower, Colour, Count
If you have 3 flower types and 3 colour types (as an example), you would have 9 records.
Then, the rest of your code would work fine.

If you want to analyze several groups, you need a fourth variable per record, indicating the group.
Group, Flower, Colour, Count
There would be nine records for each of the groups. You would need to sort by Group, before the FREQ analysis.
LVM
Valued Guide
Valued Guide
Posts: 684

Re: repeated chi-square tests

I slightly mis-interpreted the I (etc.) as a space. But your input file is still not correct, as I indicated in my original message. You need three values for each combination.
N/A
Posts: 0

Re: repeated chi-square tests

Will this input data file work instead?

DATA;
DO flower = 1 TO 3;
DO colour = I TO III;
INPUT WT @@;
OUTPUT;
END;
DATALINES;
18 15 12
44 43 34
34 31 37
;
PROC FREQ;
WEIGHT WT;
TABLES flower*colour;
EXACT FISHER
RUN;

The end result is such that flower type 1 has three colours, with 18 having colour I, 15 having colour II and 12 having colour III, and a total of 45.

The same goes for flower type 2.

If I have to sort by Group, do I just have to put in the data for Group under the datalines as well?
Valued Guide
Valued Guide
Posts: 684

Re: repeated chi-square tests

Your do loops won't work right, separate from the analysis. It is always a good idea to print the data file before the analysis to make sure you have what you think you have. I can't get into the do loop rules, but here is a direct way of getting what you want. I repeated your data a second time to show two groups. Make sure the groups are in order. There can be any number of groups.

DATA a;
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 18
2 A II 15
2 A III 12
2 B I 44
2 B II 43
2 B III 34
2 C I 34
2 C II 31
2 C III 37
;
proc print data=a;
RUN;
PROC FREQ data=a;
by group;
WEIGHT COUNT;
TABLES flowers*colours;
EXACT FISHER;
RUN;
Ask a Question
Discussion stats
  • 6 replies
  • 141 views
  • 0 likes
  • 3 in conversation