Chapter Contents |
Previous |
Next |
The FREQ Procedure |
[Creating an Output Data Set with Table Cell...;] The eye and hair color of children from two different regions of Europe are recorded in the data set Color. Instead of recording one observation per child, the data are recorded as cell counts, where the variable Count contains the number of children exhibiting each of the 15 eye and hair color combinations. The data set does not include missing combinations.
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 ;
The following statements read the Color data set and create an output data set containing the frequencies, percentages, and expected cell frequencies of the Eyes by Hair two-way table. The TABLES statement requests three tables: Eyes and Hair frequency tables and an Eyes by Hair crosstabulation table. The OUT= option creates the FreqCnt data set, which contains the crosstabulation table frequencies. The OUTEXPECT option outputs the expected cell frequencies to FreqCnt, and the SPARSE option includes the zero cell counts. The WEIGHT statement specifies that Count contains the observation weights. The following statements create Output 28.1.1 through Output 28.1.3.
proc freq data=Color; weight Count; tables Eyes Hair Eyes*Hair/out=FreqCnt outexpect sparse; title 'Eye and Hair Color of European Children'; run; proc print data=FreqCnt noobs; title2 'Output Data Set from PROC FREQ'; run;Output 28.1.1: Frequency Table
|
By default, PROC FREQ displays the variable values in alphabetical order (Output 28.1.1). The 'Eyes*Hair' specification produces a crosstabulation table (Output 28.1.2) with eye color defining the table rows and hair color defining the table columns. A zero cell count for green eyes and black hair indicates that this eye and hair color combination does not occur in the data.
Output 28.1.3: OUT= Data Set
|
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.