identifying fields with incorrect number of digits

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

identifying fields with incorrect number of digits

Raffe, Sydelle, SSA
I have two fields in my data that I need to identify as having an incorrect format. One is a 10 byte string variable that has a hyphen in it. It is incorrect if it doesn't have a hyphen and is less than 10 bytes (including the hyphen). The other is a 9 byte string variable (ssn). If it has less than 9 bytes it is incorrect. How can I do this?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: identifying fields with incorrect number of digits

Maguin, Eugene
Sydelle,

>>I have two fields in my data that I need to identify as having an
incorrect format. One is a 10 byte string variable that has a hyphen in it.
It is incorrect if it doesn't have a hyphen and is less than 10 bytes
(including the hyphen). The other is a 9 byte string variable (ssn). If it
has less than 9 bytes it is incorrect. How can I do this?


One way to do this is to search field 1 for a hyphen and check its length.
Like this but note assumptions. Assumptions: 1) if field 1 is less than 10
characters, the trailing characters are blanks. 2) the '-' character
(located on the key to the right of the '0'/')' key on a US keyboard is used
as a hyphen. If that character is not the hyphen character (and it might not
be), then you have figure out the character being used and its code. The
table in the back of the syntax references is, I think, useless for this but
somebody as spss will know or, very likely, Richard will know.


Compute err=1. /* an error is the default.
If (char.length(field1) eq 10 and index(field1,'-') gt 0) err=0.

The second problem is a simplification of the first.

Gene Maguin

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: identifying fields with incorrect number of digits

Oliver, Richard
In reply to this post by Raffe, Sydelle, SSA
Replace "string1" and "string2" with your string variable names:

compute flag1=length(rtrim(string1))< 10 or index(string1, "-")=0.
compute flag2=lentgth(rtrim(string2) < 9.

flag1=1 if string1 is less than 10 bytes or doesn't contain a hyphen. (You could, of course, compute separate flags for each condition).

flag2=1 if string 2 is less than 9 bytes.

All other cases with non-missing values will have a value of 0 for each flag variable.

I used the length function instead of char.length because that returns number of bytes, whereas char.length returns number of characters. If what you really want is number of characters, use char.length if you are using a version that supports this function. If you use char.length, you can drop the rtrim function.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Raffe, Sydelle, SSA
Sent: Wednesday, May 27, 2009 2:16 PM
To: [hidden email]
Subject: identifying fields with incorrect number of digits

I have two fields in my data that I need to identify as having an incorrect format. One is a 10 byte string variable that has a hyphen in it. It is incorrect if it doesn't have a hyphen and is less than 10 bytes (including the hyphen). The other is a 9 byte string variable (ssn). If it has less than 9 bytes it is incorrect. How can I do this?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: identifying fields with incorrect number of digits

Raffe, Sydelle, SSA
Thank you Gene and Richard. I'll check into char.length but know that  I have the rtrim backup.

-----Original Message-----
From: Oliver, Richard [mailto:[hidden email]]
Sent: Wednesday, May 27, 2009 12:35 PM
To: Raffe, Sydelle, SSA; [hidden email]
Subject: RE: identifying fields with incorrect number of digits


Replace "string1" and "string2" with your string variable names:

compute flag1=length(rtrim(string1))< 10 or index(string1, "-")=0.
compute flag2=lentgth(rtrim(string2) < 9.

flag1=1 if string1 is less than 10 bytes or doesn't contain a hyphen. (You could, of course, compute separate flags for each condition).

flag2=1 if string 2 is less than 9 bytes.

All other cases with non-missing values will have a value of 0 for each flag variable.

I used the length function instead of char.length because that returns number of bytes, whereas char.length returns number of characters. If what you really want is number of characters, use char.length if you are using a version that supports this function. If you use char.length, you can drop the rtrim function.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Raffe, Sydelle, SSA
Sent: Wednesday, May 27, 2009 2:16 PM
To: [hidden email]
Subject: identifying fields with incorrect number of digits

I have two fields in my data that I need to identify as having an incorrect format. One is a 10 byte string variable that has a hyphen in it. It is incorrect if it doesn't have a hyphen and is less than 10 bytes (including the hyphen). The other is a 9 byte string variable (ssn). If it has less than 9 bytes it is incorrect. How can I do this?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD