Login  Register

Re: How to get rid of a character/sign in string

Posted by Ruben Geert van den Berg on Jun 08, 2009; 4:48pm
URL: http://spssx-discussion.165.s1.nabble.com/Paired-test-for-3-variables-tp1089169p1089173.html

Dear Emel,
 
You could do it with replace. Here's some SPSS test data with the characters # and " " (space) in it and how to remove them. Obviously, you don't need to create new variables (you could replace Var2 and Var3 by Var) but perhaps this makes it clearer. Just mind you: all spaces and instances of # will be removed.
 
Kind regards,
 
Ruben van den Berg
 
***Create data.
 
DATA LIST FREE/Var (A5).
BEGIN DATA
"#bla" "b#la" "bl#a" "bla#" " bla" "b la" "bl a" "bla "
END DATA.
 
***Create new variables (empty).
 
STR Var2 Var3 (A5).
 
***Create Var2 (=Var with # replaced by nothing).
 
COMP Var2=REP(Var,"#","")./*REP = REPlace.
 
***Create Var3 (=Var2 with space replaced by nothing).
 
COMP Var3=REP(Var2," ","").
EXE.




 



 

> Date: Mon, 8 Jun 2009 11:49:52 -0400
> From: [hidden email]
> Subject: How to get rid of a character/sign in string
> To: [hidden email]
>
> Hi to all:
>
> As a newbie SPSS syntact-er, I apologize if my message is annoyingly simple.
> Here is the thing I need help:
>
> I have 7 digit string variable (7 digit number) with random "#" sign in it. In
> variable there are few cases where space has been used instead of "#". I want to
> get rid of both.
>
> Q1. Does the position of sign and space matter?
> Q2. Do you have any code that I can try to adjust my case?
>
> Many thanks to all!!
>
> emel
>
>
> The information in this e-mail is intended only for the person to whom it is
> addressed. If you believe this e-mail was sent to you in error and the e-mail
> contains patient information, please contact the Partners Compliance HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in error
> but does not contain patient information, please contact the sender and properly
> dispose of the e-mail.
>
> =====================
> 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


Express yourself instantly with MSN Messenger! MSN Messenger