|Date: ||Fri, 25 Jul 2003 12:05:28 +0300|
|Sender: ||"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>|
|Subject: ||Re: replacing parts of a string variable|
|Content-type: ||text/plain; charset=us-ascii|
string code1 code2 code3 (a8).
Central Statistical Bureau of Latvia
address: Lacplesa iela 1, Riga, LV-1301, Latvia
<firstname.lastname@example.org To: SPSSX-L@LISTSERV.UGA.EDU
Sent by: "SPSSX(r) Subject: Re: replacing parts of a string variable
Please respond to
a related question to this - i have a string variable 'ccode' which is
to the first slash relates to subject and mode
to the second slash relates to the academic session the programme
and the final part relates to the current year
ho do i create 3 new variables from the one string variable
thanks in advance
>>> "Marks, Jim" <Jim.Marks@lodgenet.com> 07/24/03 05:34pm >>>
This will work:
DATA LIST /strvar (A40).
Gonzales Middle School
School of Hard Knocks
University of Waterloo
Middle School of Schools
STRING newstr (A40).
DO IF INDEX(strvar,'School') GT 0.
COMPUTE #place EQ INDEX(strvar,'School').
COMPUTE #lngth EQ LENGTH(RTRIM(strvar)).
COMPUTE newstr EQ
COMPUTE newstr EQ strvar.
Note case 3-- "school" is not changed.
Note case 4-- the second instance of "School" is not affected.
Note case 5-- "Schools" is changed to "Schs".
For other words, don't forget to change the number in the second SUBSTR
in the final COMPUTE-- "School" has 6 characters.
I prefer to create new variables rather than change existing variables.
Mistakes are easier to fix that way :-)
Senior Market Analyst
LodgeNet Entertainment Corporation
From: John Diez - Network & Online Services [mailto:JDiez@rnchq.org]
Sent: Thursday, July 24, 2003 10:21 AM
Subject: replacing parts of a string variable
i have a string variable that has recurring words in it that i would
like to truncate. how can you replace part of a string? for example, i
would like every occurrence of "school" to be truncated to "sch", so the
value "Gonzales Middle School" would be "Gonzales Middle Sch". is there
a find and replace command?
The information transmitted is the property of the University of Paisley
and is intended only for the person or entity
to which it is addressed and may contain confidential and/or privileged
material. Statements and opinions expressed in this
e-mail may not represent those of the company. Any review, retransmission,
dissemination and other use of, or taking
of any action in reliance upon, this information by persons or entities
other than the intended recipient is prohibited.
If you received this in error, please contact the sender immediately and
delete the material from any computer.