How to Calculate the Mode in SAS
- 1). Prepare input dataset.
- 2). Select a procedure. Depending on the version of SAS, several procedures allow use of MODE: PROC MEANS, PROC TABULATE, PROC REPORT and PROC UNIVARIATE. UNIVARIATE is sufficient for the purpose of finding the modes of all fields in the input dataset.
- 3). Program the procedure. Sample syntax for finding the mode is:
PROC UNIVARIATE DATA=DATASET1 MODES ROUND=1 0.5 0.5;
var age height weight;
run;
The MODES option makes a table of all possible modes, i.e. for every variable listed under VAR that has at least two values the same. The procedure's default is to display only one variable's mode. Replacing MODES with MODE outputs only one variable's mode.
Replacing MODES with ALL leads to output of a table of modes as well as many other statistics.
The ROUND= option reduces the number of unique variable values, thereby reducing the memory requirement. The 1 rounds age to the nearest year. The two 0.5s round height and weight to the nearest half. - 4). Save the program, then submit it for execution.