Syntax for Finding errors

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Syntax for Finding errors

[Ela Bonbevan]
Hello all,


I have been trying to write a little bit of syntax to identify errors in
my database.  I know I am close but I can't seem to get the right syntax
for identify blank cells.  In this case the error is defined as a case
with a value in the variable "region" but no value in the
variable "country".  Region is coded 1-10 - and so is country.  I wrote
the syntax below to identify all of these error cases as a value of 1 on a
new variable "error".

This is what I have so far....

Compute error = $sysmis.
If (region > 0) and (country = sysmis) error = 1.

...but it won't work!

Many thanks
Diane
Reply | Threaded
Open this post in threaded view
|

Re: Syntax for Finding errors

Beadle, ViAnn
1. never use a construct like
 x eq sysmis
because the outcome is always missing
 
Instead do this:
 sysmis(x)
 
2. any new numeric variable is initialized to system missing so
 compute error =$sysmis.
is unnecessary
 
Handling missing values is tricky in transformations.

________________________________

From: SPSSX(r) Discussion on behalf of [Ela Bonbevan]
Sent: Wed 7/12/2006 9:06 AM
To: [hidden email]
Subject: Syntax for Finding errors



Hello all,


I have been trying to write a little bit of syntax to identify errors in
my database.  I know I am close but I can't seem to get the right syntax
for identify blank cells.  In this case the error is defined as a case
with a value in the variable "region" but no value in the
variable "country".  Region is coded 1-10 - and so is country.  I wrote
the syntax below to identify all of these error cases as a value of 1 on a
new variable "error".

This is what I have so far....

Compute error = $sysmis.
If (region > 0) and (country = sysmis) error = 1.

...but it won't work!

Many thanks
Diane
Reply | Threaded
Open this post in threaded view
|

Suggest: Warn, for missing values in comparisons

Richard Ristow
In reply to this post by [Ela Bonbevan]
This is a follow-on to thread "Syntax for Finding errors", begun Wed,
12 Jul 2006 10:06:53, but continues a topic that has gone on for much,
much longer than that: SPSS's handling of missing values in
comparisons.

At 10:06 AM 7/12/2006, [Ela Bonbevan] wrote:
>>This is what I have so far....
>>
>>Compute error = $sysmis.
>>If (region > 0) and (country = sysmis) error = 1.
>>
>>...but it won't work!

To which, at 10:34 AM 7/12/2006, Beadle, ViAnn wrote:
>Instead do this:
>  sysmis(x)

This question, or related ones, come up regularly on the List. It's
from SPSS's sophisticated handling of missing values in comparisons: A
comparison can return any of three values, 'true', 'false', and
'missing'; and a comparison in which either of the values compared is
missing, returns missing. (There are excellent rules for combining
logical values some of which may be 'missing'; see table 2-4 in the
Command syntax Reference.)

The convention is excellent, but it's confusing in practice. Partly,
that's because it was never fully implemented - except in DO IF and
ELSE IF, the results of 'false' and 'missing' tests are the same. And
in DO IF and ELSE IF, a 'missing' test means all branches of the
construct are skipped, with no notice, even if there's an ELSE clause;
that's a very well-known 'gotcha'.

Simple suggestion: Now that SPSS gives a warning if a loop exits
because MXLOOPS was reached, how about one if the logical value used in
a test is missing? (By "used in a test", I mean on IF; DO IF or ELSE
IF; SELECT IF; LOOP IF; END LOOP IF. Have I missed any?) A warning that
something unexpected had happened in a test, would be an important
start on catching and fixing the problem.


.............................
Old threads:
"What's wrong with DO IF", begun Wed, 24 Aug 2005 16:26:34;

see also,
"MISSING in DO/END IF",    begun Mon,  1 Mar 2004 16:02:35
"IF and DO IF logic",      begun Fri, 27 Aug 2004 17:12:40
"Explaining output of a do if with missing values",
                            begun Fri, 9 Sep 2005 09:59:24