The TABULATE Procedure |
Missing Values |
How a missing value for a variable in the input data set affects your output depends on how you use the variable in the PROC TABULATE step. The following table summarizes how the procedure treats missing values.
If ... | PROC TABULATE, by default, ... | To override the default ... |
---|---|---|
an observation contains a missing value for an analysis variable | excludes that observation from the calculation of statistics (except N and NMISS) for that particular variable | no alternative |
an observation contains a missing value for a class variable | excludes that observation from the table (table note 1) | use MISSING in the PROC TABULATE statement, or MISSING in the CLASS statement |
there are no data for a category | does not show the category in the table | use PRINTMISS in the TABLE statement, or use CLASSDATA= in the PROC TABULATE statement |
every observation that contributes to a table cell contains a missing value for an analysis variable | displays a missing value for any statistics (except N and NMISS) in that cell | use MISSTEXT= in the TABLE statement |
there are no data for a formatted value | does not display that formatted value in the table | use PRELOADFMT in the CLASS statement with PRINTMISS in the TABLE statement, or use CLASSDATA= in the PROC TABULATE statement, or add dummy observations to the input data set so that it contains data for each formatted value |
a FREQ variable value is missing or is less than 1 | does not use that observation to calculate statistics | no alternative |
a WEIGHT variable value is missing or 0 | uses a value of 0 | no alternative |
TABLE NOTE 1: The CLASS statement applies to all TABLE statements in a PROC TABULATE step. Therefore, if you define a variable as a class variable, PROC TABULATE omits observations that have missing values for that variable even if you do not use the variable in a TABLE statement.
This section presents a series of PROC TABULATE steps that illustrate how PROC TABULATE treats missing values. The following program creates the data set and formats that are used in this section and prints the data set. The data set COMPREV contains no missing values. (See the following figure.)
proc format; value cntryfmt 1='United States' 2='Japan'; value compfmt 1='Supercomputer' 2='Mainframe' 3='Midrange' 4='Workstation' 5='Personal Computer' 6='Laptop'; run;
data comprev; input Country Computer Rev90 Rev91 Rev92; datalines; 1 1 788.8 877.6 944.9 1 2 12538.1 9855.6 8527.9 1 3 9815.8 6340.3 8680.3 1 4 3147.2 3474.1 3722.4 1 5 18660.9 18428.0 23531.1 2 1 469.9 495.6 448.4 2 2 5697.6 6242.4 5382.3 2 3 5392.1 5668.3 4845.9 2 4 1511.6 1875.5 1924.5 2 5 4746.0 4600.8 4363.7 ;
proc print data=comprev noobs; format country cntryfmt. computer compfmt.; title 'The Data Set COMPREV'; run;
The following PROC TABULATE step produces the following figure:
proc tabulate data=comprev; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32; format country cntryfmt. computer compfmt.; title 'Revenues from Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: No Missing Values
The next program copies COMPREV and alters the data so that the eighth observation has a missing value for Computer. Except for specifying this new data set, the program that produces Computer Sales Data: Midrange, Japan, Deleted is the same as the program that produces Computer Sales Data: No Missing Values. By default, PROC TABULATE ignores observations with missing values for a class variable.
data compmiss; set comprev; if _n_=8 then computer=.; run;
proc tabulate data=compmiss; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32; format country cntryfmt. computer compfmt.; title 'Revenues from Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: Midrange, Japan, Deleted
This program adds the MISSING option to the previous program. MISSING is available either in the PROC TABULATE statement or in the CLASS statement. If you want MISSING to apply only to selected class variables, but not to others, then specify MISSING in a separate CLASS statement with the selected variables. The MISSING option includes observations with missing values of a class variable in the report. (See the following figure.)
proc tabulate data=compmiss missing; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32; format country cntryfmt. computer compfmt.; title 'Revenues from Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: Missing Values for Computer
By default, as shown in Computer Sales Data: Missing Values for Computer, PROC TABULATE displays missing values of a class variable as one of the standard SAS characters for missing values (a period, a blank, an underscore, or one of the letters A through Z). If you want to display something else instead, then you must assign a format to the class variable that has missing values, as shown in the following program. (See the following figure.)
proc format; value misscomp 1='Supercomputer' 2='Mainframe' 3='Midrange' 4='Workstation' 5='Personal Computer' 6='Laptop' .='No type given'; run;
proc tabulate data=compmiss missing; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32; format country cntryfmt. computer misscomp.; title 'Revenues for Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: Text Supplied for Missing Computer Value
By default, PROC TABULATE evaluates each page that it prints and omits columns and rows for categories that do not exist. For example, Computer Sales Data: Text Supplied for Missing Computer Value does not include a row for No type given and for United States or for Midrange and for Japan because there are no data in these categories. If you want the table to represent all possible categories, then use the PRINTMISS option in the TABLE statement, as shown in the following program. (See the following figure.)
proc tabulate data=compmiss missing; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32 printmiss; format country cntryfmt. computer misscomp.; title 'Revenues for Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: Missing Statistics Values
If some observations in a category contain missing values for analysis variables, then PROC TABULATE does not use those observations to calculate statistics (except N and NMISS). However, if each observation in a category contains a missing value, then PROC TABULATE displays a missing value for the value of the statistic. To replace missing values for analysis variables with text, use the MISSTEXT= option in the TABLE statement to specify the text to use, as shown in the following program. (See the following figure.)
proc tabulate data=compmiss missing; class country computer; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32 printmiss misstext='NO DATA!'; format country cntryfmt. computer misscomp.; title 'Revenues for Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: Text Supplied for Missing Statistics Values
PROC TABULATE prints headings only for values that appear in the input data set. For example, the format COMPFMT. provides for six possible values of Computer. Only five of these values occur in the data set COMPREV. The data set contains no data for laptop computers.
If you want to include headings for all possible values of Computer (perhaps to make it easier to compare the output with tables that are created later when you do have data for laptops), then you have three different ways to create such a table:
Use the PRELOADFMT option in the CLASS statement with the PRINTMISS option in the TABLE statement. See Using Preloaded Formats with Class Variables for another example that uses PRELOADFMT.
Use the CLASSDATA= option in the PROC TABULATE statement. See Specifying Class Variable Combinations to Appear in a Table for an example that uses the CLASSDATA= option.
Add dummy values to the input data set so that each value that the format handles appears at least once in the data set.
The following program adds the PRELOADFMT option to a CLASS statement that contains the relevant variable.
The results are shown in the following figure.
proc tabulate data=compmiss missing; class country; class computer / preloadfmt; var rev90 rev91 rev92; table computer*country,rev90 rev91 rev92 / rts=32 printmiss misstext='NO DATA!'; format country cntryfmt. computer compfmt.; title 'Revenues for Computer Sales'; title2 'for 1990 to 1992'; run;
Computer Sales Data: All Possible Computer Values Included
Understanding the Order of Headings with ORDER=DATA |
The ORDER= option applies to all class variables. Occasionally, you want to order the headings for different variables differently. One method for reordering the headings is to group the data as you want them to appear and to specify ORDER=DATA.
For this technique to work, the first value of the first class variable must occur in the data with all possible values of all the other class variables. If this criterion is not met, then the order of the headings might surprise you.
The following program creates a simple data set in which the observations are ordered first by the values of Animal, then by the values of Food. The ORDER= option in the PROC TABULATE statement orders the heading for the class variables by the order of their appearance in the data set. (See the following figure.) Although bones is the first value for Food in the group of observations where Animal=dog , all other values for Food appear before bones in the data set because bones never appears when Animal=cat . Therefore, the heading for bones in the table in the following figure is not in alphabetical order.
In other words, PROC TABULATE maintains for subsequent categories the order that was established by earlier categories. If you want to re-establish the order of Food for each value of Animal, then use BY-group processing. PROC TABULATE creates a separate table for each BY group, so that the ordering can differ from one BY group to the next.
data foodpref; input Animal $ Food $; datalines; cat fish cat meat cat milk dog bones dog fish dog meat ; proc tabulate data=foodpref format=9. order=data; class animal food; table animal*food; run;
Ordering the Headings of Class Variables
Portability of ODS Output with PROC TABULATE |
Under certain circumstances, using PROC TABULATE with the Output Delivery System produces files that are not portable. If the SAS system option FORMCHAR= in your SAS session uses nonstandard line-drawing characters, then the output might include strange characters instead of lines in operating environments in which the SAS Monospace font is not installed. To avoid this problem, specify the following OPTIONS statement before executing PROC TABULATE:
options formchar="|----|+|---+=|-/\<>*";
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.