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 (September 2010)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 14 Sep 2010 06:58:35 -0600
Reply-To:     Jon K Peck <>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Jon K Peck <>
Subject:      Re: Splitting a string
Comments: To: John F Hall <>
In-Reply-To:  <AA90C87D8AF5475DA46B4FA3FB4C1246@yourg2asvv4l2m>
Content-Type: multipart/alternative;

Just for fun, here is a one-command solution using the SPSSINC TRANS extension command available from Developer Central. (I know John won't like this, but here it is anyway.)

spssinc trans result=x y z /formula '"(\d)(\d)(\d)",f).groups()'.

It creates numeric variables x, y, and z each holding a single digit, where f is the input variable.

Regular expressions such as these provide powerful pattern-based string manipulation techniques.

Regards, Jon Peck SPSS, an IBM Company 312-651-3435

From: John F Hall <> To: SPSSX-L@LISTSERV.UGA.EDU Date: 09/13/2010 11:58 PM Subject: [SPSSX-L] Splitting a string Sent by: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>

Not often I ask for advice, but I am helping someone out with a data set which has a string variable that needs splitting. The strings consist of one letter ot two, followed by three digits, each of which indicates something different. I've sorted the letter codes manually, but I still need to generate three new variables, one for each digit eg:

f502 5 0 2 f503 5 0 3 f504 5 0 2 f521 5 2 1 fy101 1 0 1 fy102 1 0 2 fy111 1 1 1 fy121 1 2 1

I could do it manually in the Data Editor by scrolling down and deleting the letters then creating three variables arithmetically with

compute x = trunc (y/100) compute z = mod (y/10)

etc etc, but someone out there will have a much neater solution.

John Hall

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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


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