HP 3000 Manuals

MEDIAN Function [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

MEDIAN Function 

The MEDIAN function returns the content of the parameter whose value is
the middle value in a list formed by arranging the parameters in sorted
order.  The function type is numeric.

Syntax 

     FUNCTION MEDIAN ({parameter-1}...)

Parameters 

parameter-1           Must be class numeric.

Return Value 

The value returned is the content of parameter-1 having the middle value
in a list formed by arranging all the parameter-1 values in sorted order.

If the number of occurrences referenced by parameter-1 is odd, the
returned value is such that at least half of the occurrences referenced
by parameter-1 are greater than or equal to the returned value and at
least half are less than or equal.  If the number of occurrencces
referenced by parameter-1 is even, the returned value is the arithmetic
mean of the values referenced by the two middle occurrences.

The comparisons used to arrange the parameter-1 values in sorted order
are made according to the rules for simple conditions.  See the section
"Simple Conditions" in Chapter 8  for additional information.

Example 

     01  TAB.
         05  ELEMENT   PIC S999V99
                         OCCURS 4 TIMES VALUE ZERO.
     01  NUM-MEDIAN    PIC S999V99 VALUE ZERO.
          :
     MOVE 1.25 TO ELEMENT (1).
     MOVE 3.50 TO ELEMENT (2).
     MOVE 8.75 TO ELEMENT (3).
     MOVE 0.25 TO ELEMENT (4).

     COMPUTE NUM-MEDIAN = FUNCTION MEDIAN (1, 7, 9, 23, 85).
     DISPLAY NUM-MEDIAN.
     COMPUTE NUM-MEDIAN = FUNCTION MEDIAN ( ELEMENT (ALL) ).
     DISPLAY NUM-MEDIAN.

The above example displays the following:

     +009.00
     +002.37



MPE/iX 5.0 Documentation