|
Hi,
I need to identify cases of a variable aid_id where the length is less than 6. I tried the syntax below but do not get results: temp. select if length(aid_id) < 6. freq aid_id. Thanks in advance, Keval ===================== 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 |
|
Try this:
select if length(rtrim(aid_id)) < 6. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Keval Khichadia Sent: Tuesday, August 05, 2008 12:19 PM To: [hidden email] Subject: length of id Hi, I need to identify cases of a variable aid_id where the length is less than 6. I tried the syntax below but do not get results: temp. select if length(aid_id) < 6. freq aid_id. Thanks in advance, Keval ===================== 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 |
|
In reply to this post by Keval Khichadia
At 01:18 PM 8/5/2008, Keval Khichadia wrote:
>I need to identify cases of a variable aid_id where the length is >less than 6. I tried the syntax below but do not get results: >temp. >select if length(aid_id) < 6. >freq aid_id. That's a modest 'gotcha' in SPSS: LENGTH measures the length of the *whole* string, trailing blanks and all. If you apply it to a string variable, you get the variable's length, not the length of the values in it. You use RTRIM to remove the trailing blanks, and *then* use LENGTH: temp. select if length(RTRIM(aid_id)) < 6. freq aid_id. ===================== 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 |
|
Very old school, Richard(s).
With SPSS 16, there is a whole new set of character-oriented string functions. They are named with prefix CHAR, and they include CHAR.LENGTH. CHAR.LENGTH(var) returns the length in characters of var with any trailing blanks removed. We introduced this new set of functions primarily to handle Unicode characters, where the length of a character in bytes can be 1-4 but also to make handling traditional multi-byte character sets such as Japanese, Korean, and the two Chinese code pages more civilized and to avoid traps such as the one that started this thread. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Tuesday, August 05, 2008 11:43 AM To: [hidden email] Subject: Re: [SPSSX-L] length of id At 01:18 PM 8/5/2008, Keval Khichadia wrote: >I need to identify cases of a variable aid_id where the length is >less than 6. I tried the syntax below but do not get results: >temp. >select if length(aid_id) < 6. >freq aid_id. That's a modest 'gotcha' in SPSS: LENGTH measures the length of the *whole* string, trailing blanks and all. If you apply it to a string variable, you get the variable's length, not the length of the values in it. You use RTRIM to remove the trailing blanks, and *then* use LENGTH: temp. select if length(RTRIM(aid_id)) < 6. freq aid_id. ===================== 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 |
|
"Old school" also works in newer releases, whereas "new school" doesn't work in older releases.
But while we're talking about newer functionality, in Unicode mode (SET UNICODE=YES), the LENGTH function will return the number of bytes in the string, rather than the defined width of the string variable. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: Tuesday, August 05, 2008 1:21 PM To: [hidden email] Subject: Re: length of id Very old school, Richard(s). With SPSS 16, there is a whole new set of character-oriented string functions. They are named with prefix CHAR, and they include CHAR.LENGTH. CHAR.LENGTH(var) returns the length in characters of var with any trailing blanks removed. We introduced this new set of functions primarily to handle Unicode characters, where the length of a character in bytes can be 1-4 but also to make handling traditional multi-byte character sets such as Japanese, Korean, and the two Chinese code pages more civilized and to avoid traps such as the one that started this thread. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Tuesday, August 05, 2008 11:43 AM To: [hidden email] Subject: Re: [SPSSX-L] length of id At 01:18 PM 8/5/2008, Keval Khichadia wrote: >I need to identify cases of a variable aid_id where the length is >less than 6. I tried the syntax below but do not get results: >temp. >select if length(aid_id) < 6. >freq aid_id. That's a modest 'gotcha' in SPSS: LENGTH measures the length of the *whole* string, trailing blanks and all. If you apply it to a string variable, you get the variable's length, not the length of the values in it. You use RTRIM to remove the trailing blanks, and *then* use LENGTH: temp. select if length(RTRIM(aid_id)) < 6. freq aid_id. ===================== 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 ===================== 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 |
| Free forum by Nabble | Edit this page |
