What I usually do is:
if . < a < b;
This make sure observations with a=. will not
be in y.
From: David Gardner [mailto:gardner@MAIL.FPG.UNC.EDU]
Sent: Tuesday, May 28, 2002 10:10 AM
Subject: Comparisons involving missing values
Has anyone else encountered problems with missing values
(including special numeric missings) in IF statements?
Consider the following scenario. You write a SAS program that compares
variables a and b, and create an analysis data set, and the results
are wrong because the input data set contains missing values
and the boolean "missing lt nonmissing" is evaluated as true. Has that
happened to you? It is especially easy to overlook if special formats,
as DATE or TIME, are associated with the variable. I bet a lot of these
errors pass by undetected and become published research. (Not where
I work, of course! (LOL ;)).
SAS deems it noteworthy, as it should, when arithmetic operations are
on variables containing missing values.
input a b;
c = a + b;
NOTE: Missing values were generated as a result of performing an
operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 63:10
However, when boolean operations involve missing values, SAS is
/* The wrong way in many instances: */
if a lt b; /* may be wrong!!! (but SAS says nothing) */
/* The right way uses N (or NMISS) to check the number of non-missing
(or missing) values: */
if n(a,b) eq 2 and a lt b; /* right!!! */
Everyone understands that "missing lt nonmissing" is supposed to be
true, just as the result of "missing plus nonmissing" is supposed to be
missing. However, both events are probably equally
be noteworthy. If the generation of missing values as a result of
performing arithmetic operations on missing values is noteworthy, then
the generation of nonmissing values as a result of performing relational
missing values be noteworthy as well?
A little birdy has confided that some developers at SAS are considering
the possibility of adding a system option that when activated would
print a note when missing values are compared in boolean operations. No
results would change; the only change would be a new note in the log.
Conscientious SAS programmers would ensure that the note does not appear
in the log. Appearance of the note might flag a logic error. The note
turned off by using N and NMISS logic as above.
Would such an option have helped you in the past?
What do you think about the change?
If this option is created, should it be on by default?
Would such a change be troubling or beneficial?
Any thoughts on the costs and benefits?
David M. Gardner
FPG Child Development Institute
University of North Carolina at Chapel Hill
Chapel Hill, NC 27599-8185