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 16:18:57 +0200
Reply-To:     Reinhart Willers <willers@uni-duesseldorf.de>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Reinhart Willers <willers@uni-duesseldorf.de>
Subject:      Re: Splitting a string
In-Reply-To:  <OF8CA09F21.704A1ACC-ON8725779E.00470359-8725779E.0047489F@us.ibm.com>
Content-type: multipart/alternative;

Regular perl-expressions are powerfull, but the current problem ist simple. Just cut off the last three characters. This can be done with original SPSS-functions:

compute length=length(rtrim(string)) /*count the characters*/. string stringnum (a3) /*declare a string*/. compute stringnum=char.substr(string,length-2) /*cut off*/. compute numbers=NUMBER(stringnum,f3 ) /*transform into a number*/. execute.

Reinhart Willers

Am 14.09.2010 um 14:58 schrieb Jon K Peck:

> > 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 're.search(r"(\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 > peck@us.ibm.com > 312-651-3435 > > > From: John F Hall <johnfhall@orange.fr> > 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 > johnfhall@orange.fr > http://surveyresearch.weebly.com > > ===================== > 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 > >


[text/html]


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