LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2003)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 24 Jul 2003 11:34:10 -0500
Reply-To:     "Marks, Jim" <>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Marks, Jim" <>
Subject:      Re: replacing parts of a string variable
Content-Type: text/plain; charset="iso-8859-1"


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 [] 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?

Back to: Top of message | Previous page | Main SPSSX-L page