|
I have an address field that has 2 spaces instead of 1 between the street number and street name, and between the street name and any ap number.
Example: 1054 45th ST AP 3 should be 1054 45th ST AP 3 Can this syntax be modified to remove the extra space leaving one space only between components? loop if index(ssn,"-")>0. + compute substr(ssn,index(ssn,"-")) = substr(ssn,index(ssn,"-")+1). end loop. exe. ===================== 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 |
|
see if the example syntax below meets your needs.
Art Kendall Social Research Consultants data list list /mystring(a30). begin data " 1054 45th ST AP 3" "123 abc st apt 5" end data. string target(a30). loop #i=2 to 30. do if substr(mystring,#i,1) eq ' ' and substr(mystring,#i-1,1) eq ' '. compute substr(target,#i,1) = '~'. else. compute substr(target,#i,1)= substr(mystring,#i,1). end if. end loop. compute target = replace(target,'~',''). list. Raffe, Sydelle, SSA wrote: > I have an address field that has 2 spaces instead of 1 between the street number and street name, and between the street name and any ap number. > > Example: 1054 45th ST AP 3 should be 1054 45th ST AP 3 > > Can this syntax be modified to remove the extra space leaving one space only between components? > > loop if index(ssn,"-")>0. > + compute substr(ssn,index(ssn,"-")) = substr(ssn,index(ssn,"-")+1). > end loop. > exe. > > ===================== > 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
Art Kendall
Social Research Consultants |
|
In reply to this post by Raffe, Sydelle, SSA
|
|
In reply to this post by Art Kendall
Eureka -- had to change the loop #i=2 to loop #i=1 and it worked perfectly. Thank you so much.
-----Original Message----- From: Art Kendall [mailto:[hidden email]] Sent: Monday, July 21, 2008 01:57 PM To: Raffe, Sydelle, SSA Cc: [hidden email] Subject: Re: remove extra spaces in address field see if the example syntax below meets your needs. Art Kendall Social Research Consultants data list list /mystring(a30). begin data " 1054 45th ST AP 3" "123 abc st apt 5" end data. string target(a30). loop #i=2 to 30. do if substr(mystring,#i,1) eq ' ' and substr(mystring,#i-1,1) eq ' '. compute substr(target,#i,1) = '~'. else. compute substr(target,#i,1)= substr(mystring,#i,1). end if. end loop. compute target = replace(target,'~',''). list. Raffe, Sydelle, SSA wrote: > I have an address field that has 2 spaces instead of 1 between the street number and street name, and between the street name and any ap number. > > Example: 1054 45th ST AP 3 should be 1054 45th ST AP 3 > > Can this syntax be modified to remove the extra space leaving one space only between components? > > loop if index(ssn,"-")>0. > + compute substr(ssn,index(ssn,"-")) = substr(ssn,index(ssn,"-")+1). > end loop. > exe. > > ===================== > 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 |
|
Hi,
How about simply using the REPLACE function (I believe was implemented in v14+)? Remember that it replaces ALL double spaces. string target (a30). compute target = replace(mystring," ", " "). Cheers!! Albert-Jan --- On Mon, 7/21/08, Raffe, Sydelle, SSA <[hidden email]> wrote: > From: Raffe, Sydelle, SSA <[hidden email]> > Subject: Re: remove extra spaces in address field > To: [hidden email] > Date: Monday, July 21, 2008, 11:22 PM > Eureka -- had to change the loop #i=2 to loop #i=1 and it > worked perfectly. Thank you so much. > > -----Original Message----- > From: Art Kendall [mailto:[hidden email]] > Sent: Monday, July 21, 2008 01:57 PM > To: Raffe, Sydelle, SSA > Cc: [hidden email] > Subject: Re: remove extra spaces in address field > > > see if the example syntax below meets your needs. > > Art Kendall > Social Research Consultants > > > > > > data list list /mystring(a30). > begin data > " 1054 45th ST AP 3" > "123 abc st apt 5" > end data. > string target(a30). > loop #i=2 to 30. > do if substr(mystring,#i,1) eq ' ' and > substr(mystring,#i-1,1) eq ' '. > compute substr(target,#i,1) = '~'. > else. > compute substr(target,#i,1)= substr(mystring,#i,1). > end if. > end loop. > compute target = replace(target,'~',''). > list. > > Raffe, Sydelle, SSA wrote: > > I have an address field that has 2 spaces instead of 1 > between the street number and street name, and between the > street name and any ap number. > > > > Example: 1054 45th ST AP 3 should be > 1054 45th ST AP 3 > > > > Can this syntax be modified to remove the extra space > leaving one space only between components? > > > > loop if index(ssn,"-")>0. > > + compute substr(ssn,index(ssn,"-")) = > substr(ssn,index(ssn,"-")+1). > > end loop. > > exe. > > > > ===================== > > 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 |
|
I felt quite proud of myself for looking that up but for some reason it did not have the desired effect. I will have to explore it again. Thanks.
-----Original Message----- From: Albert-jan Roskam [mailto:[hidden email]] Sent: Tuesday, July 22, 2008 10:33 AM To: [hidden email]; Raffe, Sydelle, SSA Subject: Re: remove extra spaces in address field Hi, How about simply using the REPLACE function (I believe was implemented in v14+)? Remember that it replaces ALL double spaces. string target (a30). compute target = replace(mystring," ", " "). Cheers!! Albert-Jan --- On Mon, 7/21/08, Raffe, Sydelle, SSA <[hidden email]> wrote: > From: Raffe, Sydelle, SSA <[hidden email]> > Subject: Re: remove extra spaces in address field > To: [hidden email] > Date: Monday, July 21, 2008, 11:22 PM > Eureka -- had to change the loop #i=2 to loop #i=1 and it > worked perfectly. Thank you so much. > > -----Original Message----- > From: Art Kendall [mailto:[hidden email]] > Sent: Monday, July 21, 2008 01:57 PM > To: Raffe, Sydelle, SSA > Cc: [hidden email] > Subject: Re: remove extra spaces in address field > > > see if the example syntax below meets your needs. > > Art Kendall > Social Research Consultants > > > > > > data list list /mystring(a30). > begin data > " 1054 45th ST AP 3" > "123 abc st apt 5" > end data. > string target(a30). > loop #i=2 to 30. > do if substr(mystring,#i,1) eq ' ' and > substr(mystring,#i-1,1) eq ' '. > compute substr(target,#i,1) = '~'. > else. > compute substr(target,#i,1)= substr(mystring,#i,1). > end if. > end loop. > compute target = replace(target,'~',''). > list. > > Raffe, Sydelle, SSA wrote: > > I have an address field that has 2 spaces instead of 1 > between the street number and street name, and between the > street name and any ap number. > > > > Example: 1054 45th ST AP 3 should be > 1054 45th ST AP 3 > > > > Can this syntax be modified to remove the extra space > leaving one space only between components? > > > > loop if index(ssn,"-")>0. > > + compute substr(ssn,index(ssn,"-")) = > substr(ssn,index(ssn,"-")+1). > > end loop. > > exe. > > > > ===================== > > 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 |
|
How about that?
string target (a30). compute target = mystring. LOOP #I=1 to trunc(ln(length(mystring)/ln(2)))+1. compute target = replace(target, " ", " "). end loop. You could loop to "length(mystring)" instead of "trunc(ln(length(mystring)/ln(2)))+1" but if you have a large dataset the later is more efficient. Regards, George ----- Original Message ----- From: "Raffe, Sydelle, SSA" <[hidden email]> To: <[hidden email]> Sent: Tuesday, July 22, 2008 3:08 PM Subject: Re: remove extra spaces in address field >I felt quite proud of myself for looking that up but for some reason it did >not have the desired effect. I will have to explore it again. Thanks. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Tuesday, July 22, 2008 10:33 AM > To: [hidden email]; Raffe, Sydelle, SSA > Subject: Re: remove extra spaces in address field > > > Hi, > > How about simply using the REPLACE function (I believe was implemented in > v14+)? Remember that it replaces ALL double spaces. > > string target (a30). > compute target = replace(mystring," ", " "). > > Cheers!! > Albert-Jan > > > --- On Mon, 7/21/08, Raffe, Sydelle, SSA <[hidden email]> wrote: > >> From: Raffe, Sydelle, SSA <[hidden email]> >> Subject: Re: remove extra spaces in address field >> To: [hidden email] >> Date: Monday, July 21, 2008, 11:22 PM >> Eureka -- had to change the loop #i=2 to loop #i=1 and it >> worked perfectly. Thank you so much. >> >> -----Original Message----- >> From: Art Kendall [mailto:[hidden email]] >> Sent: Monday, July 21, 2008 01:57 PM >> To: Raffe, Sydelle, SSA >> Cc: [hidden email] >> Subject: Re: remove extra spaces in address field >> >> >> see if the example syntax below meets your needs. >> >> Art Kendall >> Social Research Consultants >> >> >> >> >> >> data list list /mystring(a30). >> begin data >> " 1054 45th ST AP 3" >> "123 abc st apt 5" >> end data. >> string target(a30). >> loop #i=2 to 30. >> do if substr(mystring,#i,1) eq ' ' and >> substr(mystring,#i-1,1) eq ' '. >> compute substr(target,#i,1) = '~'. >> else. >> compute substr(target,#i,1)= substr(mystring,#i,1). >> end if. >> end loop. >> compute target = replace(target,'~',''). >> list. >> >> Raffe, Sydelle, SSA wrote: >> > I have an address field that has 2 spaces instead of 1 >> between the street number and street name, and between the >> street name and any ap number. >> > >> > Example: 1054 45th ST AP 3 should be >> 1054 45th ST AP 3 >> > >> > Can this syntax be modified to remove the extra space >> leaving one space only between components? >> > >> > loop if index(ssn,"-")>0. >> > + compute substr(ssn,index(ssn,"-")) = >> substr(ssn,index(ssn,"-")+1). >> > end loop. >> > exe. >> > >> > ===================== >> > 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 > ===================== 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 |
|
Thank you all -- problem solved.
-----Original Message----- From: George Emerson D'Umbra [mailto:[hidden email]] Sent: Tuesday, July 22, 2008 11:49 AM To: Raffe, Sydelle, SSA; [hidden email] Subject: Re: Re: remove extra spaces in address field How about that? string target (a30). compute target = mystring. LOOP #I=1 to trunc(ln(length(mystring)/ln(2)))+1. compute target = replace(target, " ", " "). end loop. You could loop to "length(mystring)" instead of "trunc(ln(length(mystring)/ln(2)))+1" but if you have a large dataset the later is more efficient. Regards, George ----- Original Message ----- From: "Raffe, Sydelle, SSA" <[hidden email]> To: <[hidden email]> Sent: Tuesday, July 22, 2008 3:08 PM Subject: Re: remove extra spaces in address field >I felt quite proud of myself for looking that up but for some reason it did >not have the desired effect. I will have to explore it again. Thanks. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Tuesday, July 22, 2008 10:33 AM > To: [hidden email]; Raffe, Sydelle, SSA > Subject: Re: remove extra spaces in address field > > > Hi, > > How about simply using the REPLACE function (I believe was implemented in > v14+)? Remember that it replaces ALL double spaces. > > string target (a30). > compute target = replace(mystring," ", " "). > > Cheers!! > Albert-Jan > > > --- On Mon, 7/21/08, Raffe, Sydelle, SSA <[hidden email]> wrote: > >> From: Raffe, Sydelle, SSA <[hidden email]> >> Subject: Re: remove extra spaces in address field >> To: [hidden email] >> Date: Monday, July 21, 2008, 11:22 PM >> Eureka -- had to change the loop #i=2 to loop #i=1 and it >> worked perfectly. Thank you so much. >> >> -----Original Message----- >> From: Art Kendall [mailto:[hidden email]] >> Sent: Monday, July 21, 2008 01:57 PM >> To: Raffe, Sydelle, SSA >> Cc: [hidden email] >> Subject: Re: remove extra spaces in address field >> >> >> see if the example syntax below meets your needs. >> >> Art Kendall >> Social Research Consultants >> >> >> >> >> >> data list list /mystring(a30). >> begin data >> " 1054 45th ST AP 3" >> "123 abc st apt 5" >> end data. >> string target(a30). >> loop #i=2 to 30. >> do if substr(mystring,#i,1) eq ' ' and >> substr(mystring,#i-1,1) eq ' '. >> compute substr(target,#i,1) = '~'. >> else. >> compute substr(target,#i,1)= substr(mystring,#i,1). >> end if. >> end loop. >> compute target = replace(target,'~',''). >> list. >> >> Raffe, Sydelle, SSA wrote: >> > I have an address field that has 2 spaces instead of 1 >> between the street number and street name, and between the >> street name and any ap number. >> > >> > Example: 1054 45th ST AP 3 should be >> 1054 45th ST AP 3 >> > >> > Can this syntax be modified to remove the extra space >> leaving one space only between components? >> > >> > loop if index(ssn,"-")>0. >> > + compute substr(ssn,index(ssn,"-")) = >> substr(ssn,index(ssn,"-")+1). >> > end loop. >> > exe. >> > >> > ===================== >> > 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 > ===================== 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 George Emerson D'Umbra
Unless you're in Unicode mode (release 16 or later), the LENGTH function simply returns the right-padded "length" of the string variable, which is simply the defined width of the string variable.. In release 16 or later, use CHAR.LENGTH to get the actual length of each string value or RTRIM the string, as in:
data list list (";") /stringvar (a30). begin data a abc abcd abcde end data. compute length1=length(stringvar). compute length2=length(rtrim(stringvar)). list. In this example, length1 simply returns the defined width of the string variable, which is 30 for all cases. OTOH, length2 returns the actual length of each string value. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of D'Umbra, George Sent: Tuesday, July 22, 2008 1:49 PM To: [hidden email] Subject: Re: remove extra spaces in address field How about that? string target (a30). compute target = mystring. LOOP #I=1 to trunc(ln(length(mystring)/ln(2)))+1. compute target = replace(target, " ", " "). end loop. You could loop to "length(mystring)" instead of "trunc(ln(length(mystring)/ln(2)))+1" but if you have a large dataset the later is more efficient. Regards, George ----- Original Message ----- From: "Raffe, Sydelle, SSA" <[hidden email]> To: <[hidden email]> Sent: Tuesday, July 22, 2008 3:08 PM Subject: Re: remove extra spaces in address field >I felt quite proud of myself for looking that up but for some reason it did >not have the desired effect. I will have to explore it again. Thanks. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Tuesday, July 22, 2008 10:33 AM > To: [hidden email]; Raffe, Sydelle, SSA > Subject: Re: remove extra spaces in address field > > > Hi, > > How about simply using the REPLACE function (I believe was implemented in > v14+)? Remember that it replaces ALL double spaces. > > string target (a30). > compute target = replace(mystring," ", " "). > > Cheers!! > Albert-Jan > > > --- On Mon, 7/21/08, Raffe, Sydelle, SSA <[hidden email]> wrote: > >> From: Raffe, Sydelle, SSA <[hidden email]> >> Subject: Re: remove extra spaces in address field >> To: [hidden email] >> Date: Monday, July 21, 2008, 11:22 PM >> Eureka -- had to change the loop #i=2 to loop #i=1 and it >> worked perfectly. Thank you so much. >> >> -----Original Message----- >> From: Art Kendall [mailto:[hidden email]] >> Sent: Monday, July 21, 2008 01:57 PM >> To: Raffe, Sydelle, SSA >> Cc: [hidden email] >> Subject: Re: remove extra spaces in address field >> >> >> see if the example syntax below meets your needs. >> >> Art Kendall >> Social Research Consultants >> >> >> >> >> >> data list list /mystring(a30). >> begin data >> " 1054 45th ST AP 3" >> "123 abc st apt 5" >> end data. >> string target(a30). >> loop #i=2 to 30. >> do if substr(mystring,#i,1) eq ' ' and >> substr(mystring,#i-1,1) eq ' '. >> compute substr(target,#i,1) = '~'. >> else. >> compute substr(target,#i,1)= substr(mystring,#i,1). >> end if. >> end loop. >> compute target = replace(target,'~',''). >> list. >> >> Raffe, Sydelle, SSA wrote: >> > I have an address field that has 2 spaces instead of 1 >> between the street number and street name, and between the >> street name and any ap number. >> > >> > Example: 1054 45th ST AP 3 should be >> 1054 45th ST AP 3 >> > >> > Can this syntax be modified to remove the extra space >> leaving one space only between components? >> > >> > loop if index(ssn,"-")>0. >> > + compute substr(ssn,index(ssn,"-")) = >> substr(ssn,index(ssn,"-")+1). >> > end loop. >> > exe. >> > >> > ===================== >> > 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 > ===================== 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 |
