TABULATE Procedure

Example 3: Using Preloaded Formats with Class Variables

Features:

PROC TABULATE statement option: OUT=

CLASS statement options:
EXCLUSIVE
PRELOADFMT

TABLE statement option: PRINTMISS

Other features:

PRINT procedure

Data set: ENERGY

Details

This example does the following:
  • creates a table that includes all possible combinations of formatted class variable values (PRELOADFMT with PRINTMISS), even if those combinations have a zero frequency and even if they do not make sense
  • uses only the preloaded range of user-defined formats as the levels of class variables (PRELOADFMT with EXCLUSIVE)
  • writes the output to an output data set, and prints that data set

Program

proc tabulate data=energy format=dollar12.;
   class region division type / preloadfmt;
   var expenditures;
   table region*division,
         type*expenditures / rts=25 printmiss;
   format region regfmt. division divfmt. type usetype.;
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
proc tabulate data=energy format=dollar12. out=tabdata;
   class region division type / preloadfmt exclusive;
   var expenditures;
   table region*division,
         type*expenditures / rts=25;
   format region regfmt. division divfmt. type usetype.;
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
proc print data=tabdata;
run;

Program Description

Specify the table options.The FORMAT= option specifies DOLLAR12. as the default format for the value in each table cell.
proc tabulate data=energy format=dollar12.;
Specify subgroups for the analysis.The CLASS statement separates the analysis by values of Region, Division, and Type. PRELOADFMT specifies that PROC TABULATE use the preloaded values of the user-defined formats for the class variables.
   class region division type / preloadfmt;
Specify the analysis variable.The VAR statement specifies that PROC TABULATE calculate statistics on the Expenditures variable.
   var expenditures;
Define the table rows and columns, and specify row and column options.PRINTMISS specifies that all possible combinations of user-defined formats be used as the levels of the class variables.
   table region*division,
         type*expenditures / rts=25 printmiss;
Format the output.The FORMAT statement assigns formats to the variables Region, Division, and Type.
   format region regfmt. division divfmt. type usetype.;
Specify the titles.
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
Specify the table options and the output data set.The OUT= option specifies the name of the output data set to which PROC TABULATE writes the data.
proc tabulate data=energy format=dollar12. out=tabdata;
Specify subgroups for the analysis.The EXCLUSIVE option, when used with PRELOADFMT, uses only the preloaded range of user-defined formats as the levels of class variables.
   class region division type / preloadfmt exclusive;
Specify the analysis variable.The VAR statement specifies that PROC TABULATE calculate statistics on the Expenditures variable.
   var expenditures;
Define the table rows and columns, and specify row and column options.The PRINTMISS option is not specified in this case. If it were, then it would override the EXCLUSIVE option in the CLASS statement.
   table region*division,
         type*expenditures / rts=25;
Format the output.The FORMAT statement assigns formats to the variables Region, Division, and Type.
   format region regfmt. division divfmt. type usetype.;
Specify the titles.
   title 'Energy Expenditures for Each Region';
   title2 '(millions of dollars)';
run;
Print the output data set WORK.TABDATA.
proc print data=tabdata;
run;

Output

This output, created with the PRELOADFMT and PRINTMISS options, contains all possible combinations of preloaded user-defined formats for the class variable values. It includes combinations with zero frequencies, and combinations that make no sense, such as Northeast and Pacific.
Energy Expenditures for Each Region
This output, created with the PRELOADFMT and EXCLUSIVE options, contains only those combinations of preloaded user-defined formats for the class variable values that appear in the input data set. This output is identical to the output from Creating a Basic Two-Dimensional Table.
Energy Expenditures for Each Region
This output shows the output data set TABDATA, which was created by the OUT= option in the PROC TABULATE statement. TABDATA contains the data that is created by having the PRELOADFMT and EXCLUSIVE options specified.
Energy Expenditures for Each Region