Template for computing the median values of an attribute (for each
patient). The SQL code inserts sorted Patient_ID and attribute values into a
table, TempMed1, that automatically creates sequentially numbered records
(with the sequence number the RecID field). The maximum and minimum RecIDs for
each patient are then determined, and the “middle” RecIDs
computed. For patients with an odd number of values, there is a single
“middle” value, while for patients with an even number of values,
there are two “middle” values. The values corresponding to these
RecIDs are then extracted into another table, TempMed2, and the median for
each patient is determined by taking the average of the two values (for even
numbers) or using the single value (for odd numbers).