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 17:38:58 +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: Jon K Peck <peck@us.ibm.com>
Content-Type: multipart/alternative;

Jon

I love the fancy stuff: it's just that the kind of students I taught (and still help) have enough problems running basic SPSS syntax without having to get their heads round additional bells and whistles, especially when they have to download extensions etc. Perhaps in 5 years I'll get round to a second and third level of tutorials, but things like attitude measurement and scale construction will take precedence. Meanwhile I have to finish blocks 2 and 3 and decide how much plain English introduction to write for inferential stats without using any equations.

Neither solution from Kylie and Richard worked first time. Kylie's worked when I substituted a variable name for str. Meanwhile I had already stripped the letters off manually by copying the column to Word, using find/replace and then pasting it back into a new column. Only 15 codes and it only took a couple of minutes.

*Kylie's (amended) . COMPUTE y=NUMBER(CHAR.SUBSTR(student,CHAR.LENGTH(student)-2),f8).

* My check . compute check = y - var00004 . freq check .

check   Frequency Percent Valid Percent Cumulative Percent Valid 0 318 100.0 100.0 100.0

The following arithmetic produced the variables needed once the letters were stripped off.

compute year = trunc (y/100) . compute perform = trunc ((y - year*100)/10) . compute groupid = y - (year*100) - (perform * 10) . freq year to groupid .

year   Frequency Percent Valid Percent Cumulative Percent Valid 1 78 24.5 24.5 24.5 2 74 23.3 23.3 47.8 3 62 19.5 19.5 67.3 4 66 20.8 20.8 88.1 5 38 11.9 11.9 100.0 Total 318 100.0 100.0  

perform   Frequency Percent Valid Percent Cumulative Percent Valid 0 112 35.2 35.2 35.2 1 79 24.8 24.8 60.1 2 127 39.9 39.9 100.0 Total 318 100.0 100.0  

groupid   Frequency Percent Valid Percent Cumulative Percent Valid 1 172 54.1 54.1 54.1 2 118 37.1 37.1 91.2 3 11 3.5 3.5 94.7 4 11 3.5 3.5 98.1 5 4 1.3 1.3 99.4 6 2 .6 .6 100.0 Total 318 100.0 100.0  

Thanks to everyone else for their suggestions.

Why does the font size change irrevocably after we copy output from SPSS?

John Hall johnfhall@orange.fr http://surveyresearch.weebly.com

----- Original Message ----- From: Jon K Peck To: SPSSX-L@LISTSERV.UGA.EDU Sent: Tuesday, September 14, 2010 2:58 PM Subject: Re: Splitting a string

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