MEANS Procedure

Example 4: Using a CLASSDATA= Data Set with Class Variables

Features:
PROC MEANS statement options:
CLASSDATA=
EXCLUSIVE
FW=
MAXDEC=
PRINTALLTYPES

CLASS statement

Data sets: CAKE

CAKETYPE

Details

This example does the following:
  • specifies the field width and decimal places of the displayed statistics
  • uses only the values in CLASSDATA= data set as the levels of the combinations of class variables
  • calculates the range, median, minimum, and maximum
  • displays all combinations of the class variables in the analysis

Program

options nodate pageno=1 linesize=80 pagesize=60;
data caketype;
   input Flavor $ 1-10  Layers 12;
   datalines;
Vanilla    1
Vanilla    2
Vanilla    3
Chocolate  1
Chocolate  2
Chocolate  3
;
proc means data=cake range median min max fw=7 maxdec=0
           classdata=caketype exclusive printalltypes;
   var TasteScore;
   
   class flavor layers;
   title 'Taste Score For Number of Layers and Cake Flavor';
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=60;
Create the CAKETYPE data set. CAKETYPE contains the cake flavors and number of layers that must occur in the PROC MEANS output.
data caketype;
   input Flavor $ 1-10  Layers 12;
   datalines;
Vanilla    1
Vanilla    2
Vanilla    3
Chocolate  1
Chocolate  2
Chocolate  3
;
Specify the analyses and the analysis options. The FW= option uses a field width of seven and the MAXDEC= option uses zero decimal places to display the statistics. CLASSDATA= and EXCLUSIVE restrict the class levels to the values that are in the CAKETYPE data set. PRINTALLTYPES displays all combinations of class variables in the output.
proc means data=cake range median min max fw=7 maxdec=0
           classdata=caketype exclusive printalltypes;
Specify the analysis variable. The VAR statement specifies that PROC MEANS calculate statistics on the TasteScore variable.
   var TasteScore;
   
Specify subgroups for analysis. The CLASS statement separates the analysis by the values of Flavor and Layers. Note that these variables, and only these variables, must appear in the CAKETYPE data set.
   class flavor layers;
Specify the title.
   title 'Taste Score For Number of Layers and Cake Flavor';
run;

Output

PROC MEANS calculates statistics for the 13 chocolate and vanilla cakes. Because the CLASSDATA= data set contains 3 as the value of Layers, PROC MEANS uses 3 as a class value even though the frequency is zero.
Taste Score
Taste Score For Number of Layers and Cake Flavor