removing blanks in the middle of a string ID

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

removing blanks in the middle of a string ID

Matthew Hoover
Hello everyone,
 
I'm sorry if this has been asked before, but I can't seem to figure it out.  I have a bunch of IDs that were entered incorrectly.  About half of the IDs were entered with a blank space in the middle of the ID.  For example, I have IDs like "212 344".  When I try to covert this string variable to a number using the "number" command, I'm getting an error.  I'm hoping there is an SPSS command that can remove the blanks in the middle of an ID so I can set these to a number format.  I know there is a way to remove blanks at the beginning or end of a string, but I don't know of a way to remove them in the middle. 
 
Any suggestions?
 
Thanks!
 
Matt

--
Matthew Hoover
Research Associate
Center for Youth and Communities
Heller School for Social Policy and Management
MS035 Brandeis University
415 South Street
Waltham, MA 02454
TEL 781.736.8631
FAX 781.736.3773

Reply | Threaded
Open this post in threaded view
|

Re: removing blanks in the middle of a string ID

David Marso
Administrator
REPLACE function!
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?"
Reply | Threaded
Open this post in threaded view
|

Re: removing blanks in the middle of a string ID

Tom1234
This post was updated on .
In reply to this post by Matthew Hoover
You could use the scripting service (WinWrap basic or if you have the extensions .Net and Python)
to replace ANSI code 32 with nothing - Chr$(32) etc.
Or in syntax:
compute vartarget=replace(vartarget," ","").
:troll:

"Lo there do I see my father. Lo there do I see my mother and my sisters and my brothers. Lo there do I see the line of my people, back to the beginning. Lo, they do call to me, they bid me take my place among them, in the Halls of Valhalla, where the brave may live...forever."
Reply | Threaded
Open this post in threaded view
|

Re: removing blanks in the middle of a string ID

Rick Oliver-3
In reply to this post by Matthew Hoover
compute idvar=replace(idvar, " ", "").

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]
Phone: 312.893.4922 | T/L: 206-4922




From:        Matthew Hoover <[hidden email]>
To:        [hidden email]
Date:        06/27/2012 10:04 AM
Subject:        removing blanks in the middle of a string ID
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello everyone,
 
I'm sorry if this has been asked before, but I can't seem to figure it out.  I have a bunch of IDs that were entered incorrectly.  About half of the IDs were entered with a blank space in the middle of the ID.  For example, I have IDs like "212 344".  When I try to covert this string variable to a number using the "number" command, I'm getting an error.  I'm hoping there is an SPSS command that can remove the blanks in the middle of an ID so I can set these to a number format.  I know there is a way to remove blanks at the beginning or end of a string, but I don't know of a way to remove them in the middle. 
 
Any suggestions?
 
Thanks!
 
Matt

--

Matthew Hoover
Research Associate
Center for Youth and Communities
Heller School for Social Policy and Management
MS035 Brandeis University
415 South Street
Waltham, MA 02454
TEL 781.736.8631
FAX 781.736.3773

mhoover@...