MEANS Procedure

Example 12: Identifying the Top Three Extreme Values with the Output Statistics

Features:

PROC MEANS statement option: NOPRINT

CLASS statement

OUTPUT statement options:
statistic keywords
AUTOLABEL
AUTONAME
IDGROUP

TYPES statement

Other features:

FORMAT procedure

FORMAT statement

PRINT procedure

RENAME= data set option

Data set: Charity

Details

This example does the following:
  • suppresses the display of PROC MEANS output
  • analyzes the data for the one-way combination of the class variables and across all observations
  • stores the total and average amount of money raised in new variables
  • stores in new variables the top three amounts of money raised, the names of the three students who raised the money, the years when it occurred, and the schools the students attended
  • automatically resolves conflicts in the variable names when names are assigned to the new variables in the output data set
  • appends the statistic name to the label of the variables in the output data set that contain statistics that were computed for the analysis variable
  • assigns a format to the analysis variable so that the statistics that are computed from this variable inherit the attribute in the output data set
  • renames the _FREQ_ variable in the output data set
  • displays the output data set and its contents

Program

proc format;
   value yrFmt . = " All";
   value $schFmt ' ' = "All    ";
run;
proc means data=Charity noprint;
   class School Year;
   types () school year;
   var MoneyRaised;
   output out=top3list(rename=(_freq_=NumberStudents))sum= mean=
          idgroup( max(moneyraised) out[3] (moneyraised name
            school year)=)/autolabel autoname;
   label MoneyRaised='Amount Raised';
   format year yrfmt. school $schfmt.
          moneyraised dollar8.2;
  run;
proc print data=top3list;
   title1 'School Fund Raising Report';
   title2 'Top Three Students';
run;
proc datasets library=work nolist;
   contents data=top3list;
   title1 'Contents of the PROC MEANS Output Data Set';
run;

Program Description

Create the YRFMT. and $SCHFMT. formats. PROC FORMAT creates user-defined formats that assign the value of All to the missing levels of the class variables.
proc format;
   value yrFmt . = " All";
   value $schFmt ' ' = "All    ";
run;
Generate the default statistics and specify the analysis options. NOPRINT suppresses the display of all PROC MEANS output.
proc means data=Charity noprint;
Specify subgroups for the analysis. The CLASS statement separates the analysis by values of School and Year.
   class School Year;
Specify which subgroups to analyze. The TYPES statement requests the analysis across all the observations and for each one-way combination of School and Year.
   types () school year;
Specify the analysis variable. The VAR statement specifies that PROC MEANS calculate statistics on the MoneyRaised variable.
   var MoneyRaised;
Specify the output data set options. The OUTPUT statement creates the TOP3LIST data set. RENAME= renames the _FREQ_ variable that contains frequency count for each class level. SUM= and MEAN= specify that the sum and mean of the analysis variable (MoneyRaised) are written to the output data set. IDGROUP writes 12 variables that contain the top three amounts of money raised and the three corresponding students, schools, and years. AUTOLABEL appends the analysis variable name to the label for the output variables that contain the sum and mean. AUTONAME resolves naming conflicts for these variables.
   output out=top3list(rename=(_freq_=NumberStudents))sum= mean=
          idgroup( max(moneyraised) out[3] (moneyraised name
            school year)=)/autolabel autoname;
Format the output. The LABEL statement assigns a label to the analysis variable MoneyRaised. The FORMAT statement assigns user-defined formats to the Year and School variables and a SAS dollar format to the MoneyRaised variable.
   label MoneyRaised='Amount Raised';
   format year yrfmt. school $schfmt.
          moneyraised dollar8.2;
  run;
Print the output data set WORK.TOP3LIST.
proc print data=top3list;
   title1 'School Fund Raising Report';
   title2 'Top Three Students';
run;
Display information about the TOP3LIST data set. PROC DATASETS displays the contents of the TOP3LIST data set. NOLIST suppresses the directory listing for the WORK data library.
proc datasets library=work nolist;
   contents data=top3list;
   title1 'Contents of the PROC MEANS Output Data Set';
run;

Output

The output from PROC PRINT shows the top three values of MoneyRaised, the names of the students who raised these amounts, the schools the students attended, and the years when the money was raised. The first observation contains the overall results, the next three contain the results by year, and the final two contain the results by school. The missing class levels for School and Year are replaced with the value ALL. The labels for the variables that contain statistics that were computed from MoneyRaised include the statistic name at the end of the label.
School Fund Raising
School Fund Raising Report Top Three Students
See the TEMPLATE procedure in SAS Output Delivery System: User's Guide for an example of how to create a custom table definition for this output data set.
PROC MEANS Output Data Set
Contents of the PROC MEANS Output Data Set
Contents of the PROC MEANS Output Data Set
Contents of the PROC MEANS Output Data Set