MEANS Procedure

Example 11: Identifying an Extreme Value with the Output Statistics

Features:

CLASS statement

OUTPUT statement options:
statistic keyword
MAXID
Other features:

PRINT procedure

Data set: Charity

Details

This example does the following:
  • identifies the observations with maximum values for two variables
  • creates new variables for the maximum values
  • displays the output data set

Program

proc means data=Charity n mean range chartype;
   class School Year;
   var MoneyRaised HoursVolunteered;
   output out=Prize maxid(MoneyRaised(name)
          HoursVolunteered(name))= MostCash MostTime
          max= ;
   
   title 'Summary of Volunteer Work by School and Year';
run;
proc print data=Prize;
   title 'Best Results: Most Money Raised and Most Hours Worked';
run;

Program Description

Specify the analyses. The statistic keywords specify the statistics and their order in the output. CHARTYPE writes the _TYPE_ values as binary characters in the output data set
proc means data=Charity n mean range chartype;
Specify subgroups for the analysis. The CLASS statement separates the analysis by School and Year.
   class School Year;
Specify the analysis variables. The VAR statement specifies that PROC MEANS calculate statistics on the MoneyRaised and HoursVolunteered variables.
   var MoneyRaised HoursVolunteered;
Specify the output data set options. The OUTPUT statement writes the new variables, MostCash and MostTime, which contain the names of the students who collected the most money and volunteered the most time, respectively, to the PRIZE data set.
   output out=Prize maxid(MoneyRaised(name)
          HoursVolunteered(name))= MostCash MostTime
          max= ;
   
Specify the title.
   title 'Summary of Volunteer Work by School and Year';
run;
Print the WORK.PRIZE output data set.
proc print data=Prize;
   title 'Best Results: Most Money Raised and Most Hours Worked';
run;

Output

The first page of output shows the output from PROC MEANS with the statistics for six class levels: one for Monroe High for the years 1992, 1993, and 1994; and one for Kennedy High for the same three years.
Summary of Volunteer Work
Summary of Volunteer Work by School and Year
The output from PROC PRINT shows the maximum MoneyRaised and HoursVolunteered values and the names of the students who are responsible for them. The first observation contains the overall results, the next three contain the results by year, the next two contain the results by school, and the final six contain the results by School and Year.
Best Results
Best Results: Most Money Raised and Most Hours Worked