SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Computing Frequency Distributions
Creating Crosstabulations


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 will result, with a table for each level of the other variables.

Suppose, for example, 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 preceding the last two 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 produced by the program shown below.

     proc format;
        value weight low-139='< 140'
                     140-180='140-180'
                     181-high='> 180';
        value height 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 weight. height height.;
     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



  back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement