Using the rounding function


Frequently the data stored in a numeric column need to be categorized into a number of discreet classes.

In the following example the numeric column age will be categorized into classes using the rounding function.


EXAMPLE DATABASE: Nhanes

DATA INPUT

The table nhanes in the database Nhanes.mdb is used as input and contains the continuous values for age.



QUERY categorize4

SELECT rseqn, fseqn, ethn, sex, weight, height, age, 
       ROUND(age/10,0)*10 AS ageclass
FROM nhanes 
WHERE ageunit = "Y";

Query categorize4 produces a table that applies the categorization through rounding of the age values and adds the column ageclass.



DISCUSSION

This query uses the rounding function to convert the age recorded in years, into age classes of 10 years. The age is first divided by 10, then the decimal place is rounded, and finally the rounded value is multiplied by 10 again. The width of the classes is determined by the division/multiplication factor. In order to get age classes of width 5, use 5 as the division/multiplication factor instead of 10. This simple rounding method only produces classes of the same width.


Last modified September 23, 2008 8:49 am