Date: Tue, 14 Sep 2010 16:18:57 +0200
Reply-To: Reinhart Willers <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Reinhart Willers <email@example.com>
Subject: Re: Splitting a string
Regular perl-expressions are powerfull, but the current problem ist
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*/.
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.
> Jon Peck
> SPSS, an IBM Company
> From: John F Hall <firstname.lastname@example.org>
> 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
> 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
> 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
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD