Creating Two-Way Tables

So far, you have used the FREQ procedure to create one-way frequency tables. The table results show total frequency counts for the values within the data set. However, it is often helpful to crosstabulate frequencies with the values of other variables. For example, census data is typically crosstabulated with a variable that represents geographical regions.

The simplest crosstabulation is a two-way table. To create a two-way table, join two variables with asterisks (*) in the TABLES statement of a PROC FREQ step.


General form, TABLES statement for crosstabulation:
TABLES variable-1*variable-2 <* ... variable-n>;

where (for two-way tables)

  • variable-1 specifies table rows
  • variable-2 specifies table columns.


When crosstabulations are specified, PROC FREQ produces tables with cells that contain
  • cell frequency
  • cell percentage of total frequency
  • cell percentage of row frequency
  • cell percentage of column frequency.

For example, the following program creates the two-way table shown below.

     proc format;
        value wtfmt low-139='< 140'
                    140-180='140-180'
                    181-high='> 180';
        value htfmt low-64='< 5''5"'
                    65-70='5''5-10"'
                    71-high='> 5''10"';
     run;
     proc freq data=clinic.diabetes;
        tables weight*height;
        format weight wtfmt. height htfmt.;
     run;

Frequency
Percent
Row Pct
Col Pct
Table of Weight by Height
Weight Height Total
< 5'5" 5'5-10" > 5'10"
< 140 2
10.00
100.00
28.57
0
0.00
0.00
0.00
0
0.00
0.00
0.00
2
10.00
 
 
140-180 5
25.00
50.00
71.43
5
25.00
50.00
62.50
0
0.00
0.00
0.00
10
50.00
 
 
> 180 0
0.00
0.00
0.00
3
15.00
37.50
37.50
5
25.00
62.50
100.00
8
40.00
 
 
Total 7
35.00
8
40.00
5
25.00
20
100.00


Note that the first variable, Weight, forms the table rows, and the second variable, Height, forms the columns; reversing the order of the variables in the TABLES statement would reverse their positions in the table. Note also that the statistics are listed in the legend box.