The FREQ Procedure

# Example 5: Creating an Output Data Set Containing Chi-Square Statistics

Procedure features:
PROC FREQ statement option:
 ORDER=
OUTPUT statement options:
 OUT= statistic-keywords
TABLES statement options:
 CHISQ DEVIATION EXPECTED NOCOL NOROW
WEIGHT statement
Other features:
 PRINT procedure
Data set: COLOR

This example

• creates a 3×5 contingency table showing the joint frequency distribution for two variables

• suppresses the row and column percentages for each cell

• displays the expected frequency for each cell

• displays each cell's contribution to the total Pearson chi-square statistic

• creates an output data set with Pearson chi-square and likelihood-ratio chi-square statistics

• displays the output data set.

 ```options nodate pageno=1 pagesize=60; proc freq data=color order=data; weight count;```
 ``` tables eyes*hair /chisq expected cellchi2 norow nocol;```
 ``` output out=chisqdat pchi lrchi n nmiss; title 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color'; run;```
 ```proc print data=chisqdat noobs; title 'Chi-Square Statistics for Eye and Hair Color'; title2 'Output Data Set from the FREQ Procedure'; run;```

 The contingency table lists eye and hair color in the order that they appear in the data set. The first column label explains the contents of each table cell. The Pearson chi-square provides evidence of an association between eye and hair color (p=.007). The cell chi-square values show that most of the association is due to more green-eyed children with fair or red hair and fewer with dark or black hair. Exactly the opposite occurs with the brown-eyed children.
 The output data set has one observation that contains the sample size, number of missing observations, and chi-square statistics with the corresponding degrees of freedom and probability values.