table |
Construct a grouped frequency table, with recoding |
table |
Visualizing Categorical Data: table
$Version: 1.1 (17 Nov 2000)
Michael Friendly
York University
Construct a grouped frequency table, with recoding
The TABLE macro constructs a grouped frequency table suitable for input to
the MOSAIC or MOSMAT macros. The input data may be individual observations,
or a contingency table, which may be collapsed to fewer variables. Factor
variables may be converted to character using user-supplied formats.
The TABLE macro takes 7 keyword arguments. The VAR= parameter is required.
- DATA=
-
The name of the input dataset. [Default:
DATA=_LAST_
]
- VAR=
-
Names of all factor (classification) variables to be included in the output
dataset. The observations are summed over any other factors, weighted by
the WEIGHT= variable, if any.
- CHAR=
-
If non-blank, forces the VAR= variables to be converted to character variables (using formatted values)
in the output dataset. If CHAR= a numeric value (e.g.,
CHAR=8
), it specifies the length of each character variable; otherwise, the
character variables default to length 16.
- WEIGHT=
-
Name of a frequency variable, if the input dataset is already in frequency
form. If not specified, each observation is assumed to be one case.
- ORDER=
-
Specifies the order of the variable levels used in the PROC FREQ step.
ORDER=INTERNAL|FREQ|DATA|
FORMATTED
are valid option values.
- FORMAT=
-
A list of
variable(s),
format pairs (suitable for a FORMAT
statement). The FORMAT= option may be used to recode the values of any of the VAR= variables.
- OUT=
-
The name of output dataset. The variables in the output dataset are the VAR= variables, plus COUNT, the frequency variable for each cell. [Default:
OUT=TABLE
]
None of the factor variables may be named COUNT
.
This example reads a three-way frequency table (gender x admit x dept),
where admit and dept are numeric variables, and collapses it to a two-way
table, with Gender and Admit as character variables.
%include vcd(table); *-- or include in an autocall library;
%include vcd(mosaic);
%include data(berkeley);
%table(data=berkeley, var=gender admit, weight=freq, char=Y,
format=admit admit. gender $sex., order=data, out=berk2);
%mosaic(data=berk2, var=Gender Admit);
The formats admit.
and $sex.
are created with PROC FORMAT:
proc format;
value admit 1='Admitted' 0='Rejected';
value $sex 'M'='Male' 'F'='Female';
See also
lags Macro for lag sequential analysis
mosaic Macro interface for mosaic displays
mosmat Macro interface for mosaic matrices
sort Generalized dataset sorting by format or statistic
Previous: sort Next: triplot Up: Appendix A Top: index.html