Senior User
Posts: 1

# How do generate the group number for R & C when R *C chisqure uesd in PROC FREQ

Hi all; I want to know if there is another better way to add the group number easily,when using  the PROC FREQ procedure to caculate the P value.

The column A &column B in attachment is what i want to generate,the two columns are not included in the data set 'mergeorder'.
the want dataset is like this:
cate                   trt             COUNT         total           A           B
xxxx                   GL              xx                 xx              1            1
xxxx                   GL              xx                 xx              1            2
xxxx                   LY               xx                xx               2            1
xxxx                   LY               xx                xx               2            2
..............
the data set 'mergeorder'. has too many categories ,there are only two trt groups (GL &LY),each trt group has been caculated by 'total-count' .
Here is my approach ,

data fish;
set mergeorder;
IF TRT='GL'
THEN DO
A=1;
B=1;
OUTPUT;
END;
IF TRT='LY' THEN DO
A=2 ;
B=1;
OUTPUT;
END;
run;
data fish2;
set merge2;
COUNT=TOTAL-COUNT;OUTPUT;
run;
DATA FISH3;
SET FISH2;
IF TRT='GL'
THEN DO
A=1;
B=2;
OUTPUT;
END;
IF TRT='LY' THEN DO
A=2 ;
B=2;
OUTPUT;
END;
RUN;
DATA FISHER;
SET FISH FISH3;
RUN;
PROC SORT DATA=FISHER out=fishorder;
BY CATE;
RUN;
proc freq data=fishorder   ;
table a*b /  fisher ;
weight count/zeros;
by cate;
output out=fish_2 fisher;
run;

Thanks!
Super User
Posts: 6,770

## Re: How do generate the group number for R & C when R *C chisqure uesd in PROC FREQ

If I understand correctly, you're starting with the data set you have shown, minus the A and B columns.  Depending on what they are supposed to contain (you really have shown just an abbreviated version), here is one way to add them:

data want;

set have;

by trt notsorted;

if first.trt then do;

A + 1;

B = 1;

end;

else B + 1;

run;

Even if this isn't the right result, you will probably need some variation on these tools to get what you want.

Discussion stats