The FREQ Procedure

# Example 2: Computing Chi-Square Tests for One-Way Frequency Tables

Procedure features:
PROC FREQ statement option:
 ORDER=
BY statement
TABLES statement options:
 NOCUM TESTP=
WEIGHT statement
Other features:
 SORT procedure
Data set: COLOR

This example

• sorts a data set by geographic region

• creates a one-way frequency table for each BY group

• orders the values of the frequency table by their appearance in the input data set

• suppresses the cumulative frequencies and percentages

• computes a chi-square goodness-of-fit test for specified proportions.

The chi-square goodness-of-fit test examines whether the children's hair color has a specified multinomial distribution for two regions. The hypothesized distribution for hair color is 30 percent fair, 12 percent red, 30 percent medium, 25 percent dark, and 3 percent black.
`options nodate pageno=1 linesize=80 pagesize=60;`
 ```proc sort data=color; by region; run;```
 ```proc freq data=color order=data; weight count;```
 ` tables hair/nocum testp=(30 12 30 25 3);`
 ` by region;`
 ``` title 'Hair Color of European Children'; run;```

 The frequency table lists the variable values (hair color) in the order that they appear in the data set. The last column lists the hypothesized percentages for the chi-square test. Always check that you have ordered the TESTP= percentages to correctly match the order of the variable levels. PROC FREQ computes a chi-square statistic for each region. The chi-square statistic is significant at the .05 level for region 2 (p<=.05) but not for region 1, indicating a significant departure from the hypothesized percentages in region 2.