Dear all,
I have a scale variable say a code, to validate it ,I want to check the total number of numbers in the code. for example code total numbers 23464 5 2134 4 So like this i want to identify cases which is less than 5 and which is greater than 5 total numbers.
I tried a lot in converting scale to string and getting string length and but am not able do it. thanks to all -- Regards,
Rajesh M S |
DATA LIST Free / Code (F10.0).
BEGIN DATA 23464 2134 END DATA. String Code1 (A10). COMPUTE Code1=LTRIM(SUBSTR(STRING(Code,F10),1,RINDEX(STRING(Code,F10),"123456789",1))). Compute code2= Char.length(code1) < 5. EXECUTE . DELETE VARIABLES Code1. LIST . Code code2 23464 .00 2134 1.00 Number of cases read: 2 Number of cases listed: 2 |
In reply to this post by Rajeshms
I assume that code is numeric. Compute digits=4. If ((code/1000) ge 10) digits=5. Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Rajeshms Dear all, I have a scale variable say a code, to validate it ,I want to check the total number of numbers in the code. for example code total numbers 23464 5 2134 4 So like this i want to identify cases which is less than 5 and which is greater than 5 total numbers. I tried a lot in converting scale to string and getting string length and but am not able do it. thanks to all -- Regards, Rajesh M S |
Administrator
|
or if code > 9999 ;-)
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Ujjawal
The OP does NOT supply us with his syntax or error messages so we have no way of knowing the depth of his knowledge. Here are simple ways to test length read as string or numeric. data list list / string (a5) number (f5.0).
begin data 12345 12345 1234 1234 end data. compute strlength = length(string). recode number(1000 thru 9999=4)(9999 thru 99999=5) into numlength. list.
On Sat, Mar 23, 2013 at 12:54 AM, Ujjawal <[hidden email]> wrote: DATA LIST Free / Code (F10.0). My pictures: http://picasaweb.google.com/vab88011
Twitter: vibeadle
|
This post was updated on .
@ Viann : Please correct me if i am wrong : LENGTH function returns the length of a variable in bytes rather than the number of characters in a string
|
Administrator
|
The Universals section of the FM is your friend.
LENGTH. LENGTH(strexpr). Numeric. Returns the length of strexpr in bytes, which must be a string expression. For string variables, in Unicode mode this is the number of bytes in each value, excluding trailing blanks, but in code page mode this is the defined variable length, including trailing blanks. To get the length (in bytes) without trailing blanks in code page mode, use LENGTH(RTRIM(strexpr)).
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
char.length returns the number of characters,
not bytes, with trailing blanks removed whether you are in Unicode or code
page mode, so it is a better choice than the old length function in almost
all cases.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email], Date: 03/23/2013 01:09 PM Subject: Re: [SPSSX-L] Scale variable Length Sent by: "SPSSX(r) Discussion" <[hidden email]> The Universals section of the FM is your friend. *LENGTH*. LENGTH(strexpr). Numeric. Returns the length of strexpr in bytes, which must be a string expression. For string variables, in Unicode mode this is the number of bytes in each value, excluding trailing blanks, but in code page mode this is the defined variable length, including trailing blanks. To get the length (in bytes) without trailing blanks in code page mode, use LENGTH(RTRIM(strexpr)). Ujjawal wrote > @ Viann : Please correct me if i am wrong : LENGTH function returns the > length of a variable in bytes rather than the number of characters in a > string ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Scale-variable-Length-tp5719009p5719031.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
Administrator
|
In reply to this post by Bruce Weaver
Bruce,
I'll take your LENGTH and raise you a CHAR. CHAR.LENGTH. CHAR.LENGTH(strexpr). Numeric. Returns the length of strexpr in characters, with any trailing blanks removed. @Ujjawal: Indeed: Bruce is Absolutely Correct: "The Universals section of the FM is your friend." I sense in you someone who is very eager to learn SPSS. I promise if you take an afternoon to READ and understand this section it will likely take about 2 years off the learning process because it will all come together I predict within a month or so you will be answering other people's questions on this list. -------------------
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Thanks David.. Your solution to SPSS query opens a world of learning for me..To me you are a tech God ;)
|
In reply to this post by David Marso
Length does return bytes and not characters but the OP reports an ID
composed solely of numbers, and AFAIK, numeric digits are always one byte characters. I keep forgetting about all the char.whatever functions added in support of Unicode. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Saturday, March 23, 2013 1:21 PM To: [hidden email] Subject: Re: Scale variable Length Bruce, I'll take your LENGTH and raise you a CHAR. CHAR.LENGTH. *CHAR.LENGTH*(strexpr). Numeric. Returns the length of strexpr in characters, with any trailing blanks removed. @Ujjawal: Indeed: Bruce is Absolutely Correct: "The Universals section of the FM is your friend." I sense in you someone who is very eager to learn SPSS. I promise if you take an afternoon to READ and understand this section it will likely take about 2 years off the learning process because it will all come together I predict within a month or so you will be answering other people's questions on this list. ------------------- Bruce Weaver wrote > The Universals section of the FM is your friend. * > LENGTH * > . LENGTH(strexpr). Numeric. Returns the length of strexpr in bytes, > which must be a string expression. For string variables, in Unicode > mode this is the number of bytes in each value, excluding trailing > blanks, but in code page mode this is the defined variable length, including trailing blanks. > To get the length (in bytes) without trailing blanks in code page > mode, use LENGTH(RTRIM(strexpr)). > > Ujjawal wrote >> @ Viann : Please correct me if i am wrong : LENGTH function returns >> the length of a variable in bytes rather than the number of >> characters in a string ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Scale-variable-Length-tp571900 9p5719032.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
Administrator
|
In reply to this post by Ujjawal
Thanks, but actually I'm more of a Tech demon ;-)
I'm sure many around here would agree! --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |