MEANS Procedure

Example 6: Using Preloaded Formats with Class Variables

Features:
PROC MEANS statement options:
COMPLETETYPES
FW=
MISSING
NONOBS
CLASS statement options:
EXCLUSIVE
ORDER=
PRELOADFMT

WAYS statement

Other features:

FORMAT procedure

FORMAT statement

Data set: CAKE

Details

This example does the following:
  • specifies the field width of the statistics
  • suppresses the column with the total number of observations
  • includes all possible combinations of class variables values in the analysis even if the frequency is zero
  • considers missing values as valid class levels
  • analyzes the one-way and two-way combinations of class variables
  • assigns user-defined formats to the class variables
  • uses only the preloaded range of user-defined formats as the levels of class variables
  • orders the results by the value of the formatted data

Program

options nodate pageno=1 linesize=80 pagesize=64;
proc format;
   value layerfmt 1='single layer'
                  2-3='multi-layer'
                  .='unknown';
   value $flvrfmt (notsorted)
                  'Vanilla'='Vanilla'
                  'Orange','Lemon'='Citrus'
                  'Spice'='Spice'
                  'Rum','Mint','Almond'='Other Flavor';
run;
proc means data=cake fw=7 completetypes missing nonobs;
   class flavor layers/preloadfmt exclusive order=data;
   ways 1 2;
   var TasteScore;
   format layers layerfmt. flavor $flvrfmt.;
   title 'Taste Score For Number of Layers and Cake Flavors';
run;

Program Description

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=64;
Create the LAYERFMT. and $FLVRFMT. formats. PROC FORMAT creates user-defined formats to categorize the number of cake layers and the cake flavors. NOTSORTED keeps $FLVRFMT unsorted to preserve the original order of the format values.
proc format;
   value layerfmt 1='single layer'
                  2-3='multi-layer'
                  .='unknown';
   value $flvrfmt (notsorted)
                  'Vanilla'='Vanilla'
                  'Orange','Lemon'='Citrus'
                  'Spice'='Spice'
                  'Rum','Mint','Almond'='Other Flavor';
run;
Generate the default statistics and specify the analysis options. FW= uses a field width of seven to display the statistics. COMPLETETYPES includes class levels with a frequency of zero. MISSING considers missing values valid values for all class variables. NONOBS suppresses the N Obs column. Because no specific analyses are requested, all default analyses are performed.
proc means data=cake fw=7 completetypes missing nonobs;
Specify subgroups for the analysis. The CLASS statement separates the analysis by values of Flavor and Layers. PRELOADFMT and EXCLUSIVE restrict the levels to the preloaded values of the user-defined formats. ORDER=DATA orders the levels of Flavor and Layer by formatted data values.
   class flavor layers/preloadfmt exclusive order=data;
Specify which subgroups to analyze. The WAYS statement requests one-way and two-way combinations of class variables.
   ways 1 2;
Specify the analysis variable. The VAR statement specifies that PROC MEANS calculate statistics on the TasteScore variable.
   var TasteScore;
Format the output. The FORMAT statement assigns user-defined formats to the Flavor and Layers variables for this analysis.
   format layers layerfmt. flavor $flvrfmt.;
Specify the title.
   title 'Taste Score For Number of Layers and Cake Flavors';
run;

Output

The one-way combination of class variables appears before the two-way combination. PROC MEANS reports only the level values that are listed in the preloaded range of user-defined formats even when the frequency of observations is zero (in this case, citrus). PROC MEANS rejects entire observations based on the exclusion of any single class value in a given observation. Therefore, when the number of layers is unknown, statistics are calculated for only one observation. The other observation is excluded because the flavor chocolate was not included in the preloaded user-defined format for Flavor. The order of the levels is based on the order of the user-defined formats. PROC FORMAT automatically sorted the Layers format and did not sort the Flavor format.
Taste Score for Number of Layers
Taste Score For Number of Layers and Cake Flavors