The UNIVARIATE Procedure

Example 4.2 Calculating Modes

An instructor is interested in calculating all the modes of the scores on a recent exam. The following statements create a data set named Exam, which contains the exam scores in the variable Score:

data Exam;
   label Score = 'Exam Score';
   input Score @@;
   datalines;
81 97 78 99 77 81 84 86 86 97
85 86 94 76 75 42 91 90 88 86
97 97 89 69 72 82 83 81 80 81
;

The following statements use the MODES option to request a table of all possible modes:

title 'Table of Modes for Exam Scores';
ods select Modes;
proc univariate data=Exam modes;
   var Score;
run;

The ODS SELECT statement restricts the output to the "Modes" table; see the section ODS Table Names.

Output 4.2.1: Table of Modes Display

Table of Modes for Exam Scores

The UNIVARIATE Procedure
Variable: Score (Exam Score)

Modes
ModeCount
814
864
974


By default, when the MODES option is used and there is more than one mode, the lowest mode is displayed in the "BasicMeasures" table. The following statements illustrate the default behavior:

title 'Default Output';
ods select BasicMeasures;
proc univariate data=Exam;
   var Score;
run;

Output 4.2.2: Default Output (Without MODES Option)

Default Output

The UNIVARIATE Procedure
Variable: Score (Exam Score)

Basic Statistical Measures
LocationVariability
Mean83.66667Std Deviation11.08069
Median84.50000Variance122.78161
Mode81.00000Range57.00000
  Interquartile Range10.00000

Note: The mode displayed is the smallest of 3 modes with a count of 4.



The default output displays a mode of 81 and includes a note regarding the number of modes; the modes 86 and 97 are not displayed. The ODS SELECT statement restricts the output to the "BasicMeasures" table; see the section ODS Table Names.

A sample program for this example, uniex02.sas, is available in the SAS Sample Library for Base SAS software.

Last updated: April 16, 2025