Chapter Contents

Previous

Next
The FREQ Procedure

Example 1: Creating an Output Data Set with Table Cell Frequencies


Procedure features:
TABLES statement,
multiple requests
TABLES statement options:
OUT=
OUTEXPECT
SPARSE
WEIGHT statement
Other features:
PRINT procedure

This example


Program

options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
data color;
   input Region Eyes $ Hair $ Count @@;
   label eyes='Eye Color'
         hair='Hair Color'
         region='Geographic Region';
   datalines;
1 blue  fair    23  1 blue  red      7  1 blue  medium  24
1 blue  dark    11  1 green fair    19  1 green red      7
1 green medium  18  1 green dark    14  1 brown fair    34
1 brown red      5  1 brown medium  41  1 brown dark    40
1 brown black    3  2 blue  fair    46  2 blue  red     21
2 blue  medium  44  2 blue  dark    40  2 blue  black    6
2 green fair    50  2 green red     31  2 green medium  37
2 green dark    23  2 brown fair    56  2 brown red     42
2 brown medium  53  2 brown dark    54  2 brown black   13
;
 Note about code
proc freq data=color;
   weight count;
 Note about code
   tables eyes hair eyes*hair/out=freqcnt outexpect
                                             sparse;
 Note about code
   title 'Eye and Hair Color of European Children';
run;
 Note about code
proc print data=freqcnt noobs;
   title2 'Output Data Set from PROC FREQ';
run;


Output
By default, PROC FREQ lists the variable values in alphabetical order. Because Eyes*Hair requests a crosstabulation table, the table rows are eye color and the table columns are hair color. A zero cell count for green eyes and black hair indicates that this eyes and hair combination does not occur in the data. [HTML Output]
 [Listing Output]
The output data set contains frequency counts and percentages for the last table. The data set also includes an observation for the zero cell count and a variable with the expected cell frequency for each table cell. [HTML Output]
 [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.