Creating N-Way Tables

For a frequency analysis of more than two variables, use PROC FREQ to create n-way crosstabulations. A series of two-way tables is produced, with a table for each level of the other variables.

For example, suppose you want to add the variable Sex to your crosstabulation of Weight and Height in the data set Clinic.Diabetes. Add Sex to the TABLES statement, joined to the other variables with an asterisk (*).

     tables sex*weight*height;


Determining the Table Layout

The order of the variables is important. In n-way tables, the last two variables of the TABLES statement become the two-way rows and columns. Variables that precede the last two variables in the TABLES statement stratify the crosstabulation tables.

            levels
            v
     tables sex*weight*height;
                ^      ^
                rows + columns = two-way tables

Notice the structure of the output that is produced by the program 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 sex*weight*height;
        format weight wtfmt. height htfmt.;
     run;

Frequency
Percent
Row Pct
Col Pct
Table 1 of Weight by Height
Controlling for Sex=F
Weight Height Total
< 5'5" 5'5-10" > 5'10"
< 140 2
18.18
100.00
28.57
0
0.00
0.00
0.00
0
0.00
0.00
.
2
18.18
 
 
140-180 5
45.45
55.56
71.43
4
36.36
44.44
100.00
0
0.00
0.00
.
9
81.82
 
 
> 180 0
0.00
.
0.00
0
0.00
.
0.00
0
0.00
.
.
0
0.00
 
 
Total 7
63.64
4
36.36
0
0.00
11
100.00

Frequency
Percent
Row Pct
Col Pct
Table 2 of Weight by Height
Controlling for Sex=M
Weight Height Total
< 5'5" 5'5-10" > 5'10"
< 140 0
0.00
.
.
0
0.00
.
0.00
0
0.00
.
0.00
0
0.00
 
 
140-180 0
0.00
0.00
.
1
11.11
100.00
25.00
0
0.00
0.00
0.00
1
11.11
 
 
> 180 0
0.00
0.00
.
3
33.33
37.50
75.00
5
55.56
62.50
100.00
8
88.89
 
 
Total 0
0.00
4
44.44
5
55.56
9
100.00