SUGI 24 Advanced Features of PROC TABULATE
Advanced Features of PROC TABULATE
Thomas J. Winn Jr., Texas State Comptroller's Office, Austin, Texas
ABSTRACT
The hands-on workshop associated with this paper will provide participants with practical information regarding some advanced features of PROC TABULATE. It will include a review of the basic syntax for PROC TABULATE. It also will cover methods for customizing the appearance of tables generated by PROC TABULATE (formatting, modifying table outlining characters, removing separator lines, changing headings, and changing the width of cells), for using PROC TABULATE to compute and to display percentages and other quotients, and for using PROC TABULATE for displaying statistical results.
DATA USED FOR EXAMPLES
This paper will utilize a certain SAS data file, PRDSALE, from the Release 7.00 SASHELP data library, as well as a SAS data file created by the following SAS DATA step (representing a hypothetical used car dealer’s current inventory of Saturn automobiles):
DATA SATURN;
LENGTH COLOR $10 TRANSM $9;
INPUT YEAR MODEL $ PRICE MILEAGE
COLOR $ TRANSM $ AC;
DATALINES;
96 SC2 12475 23705 white automatic 1
96 SL2 8488 55460 black manual 1
99 SL1 14007 3015 dark_green automatic 0
96 SL2 11048 44480 purple automatic 0
96 SC2 11224 14433 red manual 0
94 SC2 7884 85201 med-blue automatic 0
97 SW2 12668 31912 white automatic 1
95 SL1 9464 29734 blue_green automatic 1
96 SL2 11264 24424 copper automatic 1
93 SL2 8442 49770 blue_green automatic 0
97 SL2 12996 19830 white automatic 1
98 SC2 13848 20004 white automatic 0
98 SL1 12998 13454 silver automatic 1
96 SL2 10994 67663 light_plum manual 1
97 SW2 13628 20789 gold automatic 1
96 SL1 9996 44084 dark_green automatic 1
95 SL1 8588 67716 med_blue manual 1
95 SC2 8968 80931 red manual 0
93 SL2 7965 77004 med_blue automatic 1
97 SC2 13998 29778 silver automatic 1
96 SL2 12248 14543 gold automatic 1
94 SC1 8996 57688 plum manual 1
95 SC1 9428 49862 red manual 1
96 SC2 11468 64401 purple automatic 1
97 SW2 12994 17422 white manual 0
;;;;
REVIEW OF ELEMENTARY CONCEPTS REGARDING PROC TABULATE
Introduction to PROC TABULATE
PROC TABULATE is used to build tabular summary reports containing descriptive statistical information, including hierarchical relationships among variables. PROC TABULATE is the SAS® System’s implementation of TPL (Table
Producing Language), which was developed at the U.S. Bureau
of Labor Statistics during the 1970’s, for generating tabular
reports of descriptive statistics involving employment data.
PROC TABULATE is more powerful for producing tabulations
than PROC FREQ, and it is a more flexible statistical report
writer than PROC MEANS.
Basic Syntax for PROC TABULATE
A general form for a PROC TABULATE step is:
PROC TABULATE <option-list>;
CLASS class-variable-list;
VAR analysis-variable-list;
TABLE <<page-expression,> row-expression,>
column-expression </ table-option-list>;
BY <NOTSORTED> <DESCENDING> variable-1
< … <DESCENDING> variable-n>;
FORMAT variable-list-1 format-1
< … variable-list-n format-n>;
FREQ variable;
KEYLABEL keyword-1=‘description-1’
< … keyword-n=“description-n’>;
LABEL variable-1=‘label-1’ <…variable-n=‘label-n’>;
WEIGHT variable;
TITLE ‘text’;
The PROC TABULATE statement invokes the procedure and
specifies certain options. The most commonly-used options
are: DATA=SAS-data-file, which specifies the data set to be
used as input by the procedure, and FORMAT=numeric-
format, which determines the width of each cell (the
intersection of a row and a column of a PROC TABULATE
summary table) in the table. The MISSING option requests
that missing values be regarded as valid levels for classification
variables. Unless the MISSING option is specified,
observations with missing values for class variables will not be
included in the analysis. The NOSEPS option removes the
interior horizontal lines from the printed report.
It is a requirement that every PROC TABULATE step must
include a PROC TABULATE statement, either a CLASS
statement or a VAR statement, or both, and a TABLE
statement. Each variable appearing in a TABLE statement
must be mentioned in either the CLASS statement or the VAR
statement. Variables may not be mentioned in both the CLASS
and the VAR statements.
Coding PROC TABULATE
Before writing any SAS code for PROC TABULATE, the
programmer needs to decide what the final report should look
like. It is essential to have the fundamental design of the
pages, row, and columns of the table clearly in mind. This is
the vision which will determine the particular code to be used.
The following is an example of a table generated by PROC
TABULATE from the SATURN data set:
Hands-on Workshops
Paper 153
我要评论