SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Tabular Reports
Lesson Summary

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.


Setting Up a Table
Before you begin writing a PROC TABULATE step, it's a good idea to sketch the table you want. After you sketch the table, you can write the basic code to compute the statistics that you want to display. When you're satisfied with the basic report, you can add options and statements to modify its appearance.

Beginning Your PROC TABULATE Step
Before producing a report, you must assign a libref to the SAS data library storing the data set to be used. You can also set system options to control the appearance of your report. Then you submit a PROC TABULATE step.

Specifying Variables
Using PROC TABULATE, you specify variables as class variables (to classify your data into groups) or analysis variables (to analyze your data).

Describing the Table
Dimension expressions in the TABLE statement specify what variables and statistics appear in each dimension of the table. Commas separate the dimensions. Dimension expressions can contain operators (such as commas, asterisks, and parentheses) that you use to combine elements to produce the table.

Specifying Statistics
To request a statistic, you use an operator, the asterisk (*), to attach the statistic to the variable. If you specify only class variables in your TABLE statement, the default statistic is N (frequency). The only statistics you can request are N and PCTN (percent of total frequency). If you specify any analysis variables in your TABLE statement, the default statistic is SUM. You can request any statistic to be computed on the analysis variables. Statistics can be specified in any dimension, but they must all be in the same dimension.

Selecting Observations
As with other procedure output, you can select observations using the WHERE statement in your PROC TABULATE step.

Specifying Totals
To summarize all categories, you can use the special class variable ALL in your TABLE statement.

Labeling Keywords for Statistics and ALL
You can use the KEYLABEL statement to change headings for statistics or ALL.

Enhancing Your Table
You can use TITLE, FOOTNOTE, and LABEL statements with PROC TABULATE to enhance your tables.

Formatting the Table
To specify a new format for all table cells, use the FORMAT= option in the PROC TABULATE statement. You can specify any SAS or user-defined format. The default format is 12.2.

Creating One- and Three-Dimensional Tables
You can modify the structure of tables by removing or adding dimension expressions.


II. Syntax

To go to the page where a statement or option was presented, select a link.

LIBNAME libref  'SAS-data-library';
PROC TABULATE DATA=SAS-data-set FORMAT=format.;
      CLASS variable(s);
      VAR variable(s);
      TABLE page-expression,row-expression,column-expression / 
                <option(s)>;
      KEYLABEL keyword='text';
      LABEL variable1='label' variable2='label';
RUN;



III. Sample Program
     libname clinic 'c:\users\reports\year5\data';
     proc tabulate data=clinic.admit format=6.;
        class actlevel sex;
        var fee;
        table fee;
        table actlevel all,fee;
        table sex,actlevel all,fee;
        keylabel all='All Patients';           
     run;


IV. Points to Remember
  • Each variable listed in the TABLE statement must be specified in either a CLASS or VAR statement (but not in both).

  • Class variables can be character or numeric, but character variables must always be class variables.

  • The same variable cannot appear in both the CLASS statement and the VAR statement in the same step.

  • When you use the FORMAT= option, be sure to specify a format wide enough for the largest possible value or heading. When you specify the cell width, don't count the vertical bars that outline the cell.



back||next


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

Terms of Use & Legal Information | Privacy Statement