Example 36.6 Output Data Set of ChiSquare Statistics
This example uses the Color data from Example 36.1 to output the Pearson chisquare and the likelihoodratio chisquare statistics to a SAS data set. The following PROC FREQ statements create a twoway table of eye color versus hair color.
proc freq data=Color order=data;
tables Eyes*Hair / expected cellchi2 norow nocol chisq;
output out=ChiSqData n nmiss pchi lrchi;
weight Count;
title 'ChiSquare Tests for 3 by 5 Table of Eye and Hair Color';
run;
proc print data=ChiSqData noobs;
title1 'ChiSquare Statistics for Eye and Hair Color';
title2 'Output Data Set from the FREQ Procedure';
run;
The EXPECTED option displays expected cell frequencies in the crosstabulation table, and the CELLCHI2 option displays the cell contribution to the overall chisquare. The NOROW and NOCOL options suppress the display of row and column percents in the crosstabulation table. The CHISQ option produces chisquare tests.
The OUTPUT statement creates the ChiSqData output data set and specifies the statistics to include. The N option requests the number of nonmissing observations, the NMISS option stores the number of missing observations, and the PCHI and LRCHI options request Pearson and likelihoodratio chisquare statistics, respectively, together with their degrees of freedom and values.
The preceding statements produce Output 36.6.1 and Output 36.6.2. The contingency table in Output 36.6.1 displays eye and hair color in the order in which they appear in the Color data set. The Pearson chisquare statistic in Output 36.6.2 provides evidence of an association between eye and hair color (=0.0073). The cell chisquare values show that most of the association is due to more greeneyed children with fair or red hair and fewer with dark or black hair. The opposite occurs with the browneyed children.
Output 36.6.3 displays the output data set created by the OUTPUT statement. It includes one observation that contains the sample size, the number of missing values, and the chisquare statistics and corresponding degrees of freedom and values as in Output 36.6.2.
Output 36.6.1
Contingency Table
Output 36.6.2
ChiSquare Statistics
8 
20.9248 
0.0073 
8 
25.9733 
0.0011 
1 
3.7838 
0.0518 

0.1657 


0.1635 


0.1172 

Output 36.6.3
Output Data Set
762 
0 
20.9248 
8 
.007349898 
25.9733 
8 
.001061424 
Copyright © SAS Institute Inc. All rights reserved.