| Date: | Fri, 25 Jul 2003 12:05:28 +0300 |
| Reply-To: | Martins.Liberts@csb.gov.lv |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Martins.Liberts@csb.gov.lv |
| Subject: | Re: replacing parts of a string variable |
|
| Content-type: | text/plain; charset=us-ascii |
|---|
Hi Muir,
string code1 code2 code3 (a8).
comp code1=substr(ccode,1,6).
comp code2=substr(ccode,8,3).
comp code3=substr(ccode,12,3).
exe.
--
Martins Liberts
Central Statistical Bureau of Latvia
address: Lacplesa iela 1, Riga, LV-1301, Latvia
phone: 371-7366877
email: martins.liberts@csb.gov.lv
Muir Houston
<hous-ca0@wpmail.pais To: SPSSX-L@LISTSERV.UGA.EDU
ley.ac.uk> cc:
Sent by: "SPSSX(r) Subject: Re: replacing parts of a string variable
Discussion"
<SPSSX-L@LISTSERV.UGA
.EDU>
25.07.2003 11:55
Please respond to
Muir Houston
Hi all,
a related question to this - i have a string variable 'ccode' which is
formatted:
ACCZFO/001/1AA
to the first slash relates to subject and mode
to the second slash relates to the academic session the programme
starts
and the final part relates to the current year
ho do i create 3 new variables from the one string variable
thanks in advance
muir houston
>>> "Marks, Jim" <Jim.Marks@lodgenet.com> 07/24/03 05:34pm >>>
John:
This will work:
DATA LIST /strvar (A40).
BEGIN DATA
Gonzales Middle School
School of Hard Knocks
University of Waterloo
Middle School of Schools
END DATA.
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
CONCAT(SUBSTR(strvar,1,#place-1),'Sch',SUBSTR(strvar,#place+6,
#lngth-#place+6)).
ELSE.
COMPUTE newstr EQ strvar.
END IF.
EXECUTE.
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 :-)
Jim Marks
Senior Market Analyst
LodgeNet Entertainment Corporation
-----Original Message-----
From: John Diez - Network & Online Services [mailto:JDiez@rnchq.org]
Sent: Thursday, July 24, 2003 10:21 AM
To: SPSSX-L@LISTSERV.UGA.EDU
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?
Legal disclaimer
--------------------------
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.
--------------------------
|