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 09:35:18 +0200
Reply-To:     John F Hall <johnfhall@orange.fr>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         John F Hall <johnfhall@orange.fr>
Subject:      Re: Splitting a string
Comments: To: kylie.lange@adelaide.edu.au
Content-Type: multipart/alternative;

Kylie, Richard

Barely had time to get my breakfast and already 2 solutions. Richard's will save some complex arithmetic, but Kylie's syntax will come in handy should I need something similar in future. Always something new to learn!

Mille fois merci.

John ----- Original Message ----- From: Kylie Lange To: SPSSX-L@LISTSERV.UGA.EDU Sent: Tuesday, September 14, 2010 8:05 AM Subject: Re: Splitting a string

Hi John,

If it is always the last three characters of the string that hold the digits you need, then the following should create the numeric variable you can do the arithmetic on:

COMPUTE y=NUMBER(CHAR.SUBSTR(str,CHAR.LENGTH(str)-2),f8).

Cheers, Kylie.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of John F Hall Sent: Tuesday, 14 September 2010 3:23 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Splitting a string

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

===================== 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