SMALLEST Function

Returns the kth smallest nonmissing value.

Category: Descriptive Statistics

Syntax

SMALLEST (k, value-1<, value-2... > )

Required Arguments

k

is a numeric constant, variable, or expression that specifies which value to return.

value

specifies a numeric constant, variable, or expression.

Details

If k is missing, less than zero, or greater than the number of values, the result is a missing value and _ERROR_ is set to 1. Otherwise, if k is greater than the number of non-missing values, the result is a missing value but _ERROR_ is not set to 1.

Comparisons

The SMALLEST function differs from the ORDINAL function in that the SMALLEST function ignores missing values, but the ORDINAL function counts missing values.

Example

This example compares the values that are returned by the SMALLEST function with values that are returned by the ORDINAL function.
data comparison;
   label smallest_num='SMALLEST Function' ordinal_num='ORDINAL Function';
   do k = 1 to 4;
      smallest_num = smallest(k, 456, 789, .Q, 123);
      ordinal_num  = ordinal (k, 456, 789, .Q, 123);
      output;
   end; 
run;
proc print data=comparison label noobs;
   var k smallest_num ordinal_num;
   title 'Results From the SMALLEST and the ORDINAL Functions';
run;
Comparison of Values: The SMALLEST and the ORDINAL Functions
Comparison of Values: The SMALLEST and the ORDINAL Functions