MEANS Procedure

Example 9: Computing Different Output Statistics for Several Variables

Features:
PROC MEANS statement options:
DESCEND
NOPRINT

CLASS statement

OUTPUT statement options: statistic keywords

Other features:

PRINT procedure

WHERE= data set option

Data set: GRADE

Details

This example does the following:
  • suppresses the display of PROC MEANS output
  • stores the statistics for the class level and combinations of class variables that are specified by WHERE= in the output data set
  • orders observations in the output data set by descending _TYPE_ value
  • stores the mean exam scores and mean final grades without assigning new variables names
  • stores the median final grade in a new variable
  • displays the output data set

Program

options nodate pageno=1 linesize=80 pagesize=60;
proc means data=Grade noprint descend;
   class Status Year;
   var Score FinalGrade;
   output out=Sumdata (where=(status='1' or _type_=0))
          mean= median(finalgrade)=MedianGrade;
run;
proc print data=Sumdata;
   title 'Exam and Course Grades for Undergraduates Only';
   title2 'and for All Students';
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;
Specify the analysis options. NOPRINT suppresses the display of all PROC MEANS output. DESCEND orders the observations in the OUT= data set by descending _TYPE_ value.
proc means data=Grade noprint descend;
Specify subgroups for the analysis. The CLASS statement separates the analysis by values of Status and Year.
   class Status Year;
Specify the analysis variables. The VAR statement specifies that PROC MEANS calculate statistics on the Score and FinalGrade variables.
   var Score FinalGrade;
Specify the output data set options. The OUTPUT statement writes the mean for Score and FinalGrade to variables of the same name. The median final grade is written to the variable MedianGrade. The WHERE= data set option restricts the observations in SUMDATA. One observation contains overall statistics (_TYPE_=0). The remainder must have a status of 1.
   output out=Sumdata (where=(status='1' or _type_=0))
          mean= median(finalgrade)=MedianGrade;
run;
Print the output data set WORK.SUMDATA.
proc print data=Sumdata;
   title 'Exam and Course Grades for Undergraduates Only';
   title2 'and for All Students';
run;

Output

The first three observations contain statistics for the class variable levels with a status of 1. The last observation contains the statistics for all the observations (no subgroup). Score contains the mean test score and FinalGrade contains the mean final grade.
Exam and Course Grades
Exam and Course Grades for Undergraduates Only and for All Students