MEANS Procedure

Example 5: Using Multilabel Value Formats with Class Variables

Features:
PROC MEANS statement options:
statistic keywords
FW=
NONOBS
CLASS statement options:
MLF
ORDER=

TYPES statement

Other features:

FORMAT procedure

FORMAT statement

Data set: CAKE

Details

This example does the following:
  • computes the statistics for the specified keywords and displays them in order
  • specifies the field width of the statistics
  • suppresses the column with the total number of observations
  • analyzes the data for the one-way combination of cake flavor and the two-way combination of cake flavor and participant's age
  • assigns user-defined formats to the class variables
  • uses multilabel formats as the levels of class variables
  • orders the levels of the cake flavors by the descending frequency count and orders the levels of age by the ascending formatted values

Program

options nodate pageno=1 linesize=80 pagesize=64;
proc format;
   value $flvrfmt
                'Chocolate'='Chocolate'
                'Vanilla'='Vanilla'
                'Rum','Spice'='Other Flavor';
   value agefmt (multilabel)
                  15 - 29='below 30 years'
                  30 - 50='between 30 and 50'
                  51 - high='over 50 years'
                  15 - 19='15 to 19'
                  20 - 25='20 to 25'
                  25 - 39='25 to 39'
                  40 - 55='40 to 55'
                  56 - high='56 and above';
run;   
proc means data=cake fw=6 n min max median nonobs;
   class flavor/order=data;
   class  age /mlf order=fmt;
    types flavor flavor*age;
   var TasteScore;
   format age agefmt. flavor $flvrfmt.;
   title 'Taste Score for Cake Flavors and Participant''s Age';
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 $FLVRFMT. and AGEFMT. formats. PROC FORMAT creates user-defined formats to categorize the cake flavors and ages of the participants. MULTILABEL creates a multilabel format for Age. A multilabel format is one in which multiple labels can be assigned to the same value, in this case because of overlapping ranges. Each value is represented in the output for each range in which it occurs.
proc format;
   value $flvrfmt
                'Chocolate'='Chocolate'
                'Vanilla'='Vanilla'
                'Rum','Spice'='Other Flavor';
   value agefmt (multilabel)
                  15 - 29='below 30 years'
                  30 - 50='between 30 and 50'
                  51 - high='over 50 years'
                  15 - 19='15 to 19'
                  20 - 25='20 to 25'
                  25 - 39='25 to 39'
                  40 - 55='40 to 55'
                  56 - high='56 and above';
run;   
Specify the analyses and the analysis options. FW= uses a field width of six to display the statistics. The statistic keywords specify the statistics and their order in the output. NONOBS suppresses the N Obs column.
proc means data=cake fw=6 n min max median nonobs;
Specify subgroups for the analysis. The CLASS statements separate the analysis by values of Flavor and Age. ORDER=DATA orders values according to their order in the input data set. ORDER=FMT orders the levels of Age by ascending formatted values. MLF specifies that multilabel value formats be used for Age.
   class flavor/order=data;
   class  age /mlf order=fmt;
Specify which subgroups to analyze. The TYPES statement requests the analysis for the one-way combination of Flavor and the two-way combination of Flavor and Age.
    types flavor flavor*age;
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 Age and Flavor variables for this analysis.
   format age agefmt. flavor $flvrfmt.;
Specify the title.
   title 'Taste Score for Cake Flavors and Participant''s Age';
run;

Output

The one-way combination of class variables appears before the two-way combination. A field width of six truncates the statistics to four decimal places. For the two-way combination of Age and Flavor, the total number of observations is greater than the one-way combination of Flavor. This situation arises because of the multilabel format for age, which maps one internal value to more than one formatted value. The order of the levels of Flavor is based on the frequency count for each level. The order of the levels of Age is based on the order of the user-defined formats.
Taste Score for Cake Flavors
Taste Score for Cake Flavors and Participant's Age