|
Using codes for counting the missing (NULL) values
EXAMPLE DATABASE: NhanesDATA INPUTTable nhanes in the database Nhanes.mdb is used as input.
QUERY count_missingSELECT ethn, sex,
SUM(IIF(height IS NULL, 1, 0)) AS missing_height,
SUM(IIF(weight IS NULL, 1, 0)) AS missing_weight
FROM nhanes
GROUP BY ethn, sex
ORDER BY ethn, sex;
Query count_missing tabulates the number of all the missing data per ethnicity and sex.
DISCUSSIONThe count_missing query works in a way that the missing heights and weights are coded first. The codes will be 1 for missing values and 0 for non-missing values. The query uses the IIF( ) function to implement the codes. It has three parameters: (<condition>, <return value if condition is true>, <return value if condition is false>). SELECT ethn, sex,
IIF(height is null, 1, 0) AS missing_height,
IIF(weight is null, 1, 0) AS missing_weight
FROM nhanes;
In the query, IIF(height is null, 1, 0) statement means that, if the height is null, assign 1 as the value for missing_height, otherwise, assign 0 as the value. The same principle applies to the missing_weight column.
SELECT ethn, sex,
SUM(IIF(height IS NULL, 1, 0)) AS missing_height,
SUM(IIF(weight IS NULL, 1, 0)) AS missing_weight
FROM nhanes
GROUP BY ethn, sex
ORDER BY ethn, sex;
Last modified September 23, 2008 9:16 am
|