recoding

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

recoding

Johnny Amora
A string variable has values in the form of course-yearlevel (such as MATH-1, MATH-2, MATH-3, MATH-4,SCIENCE-1,SCIENCE-2,...., et cetera).  I want to split it into two variables where the first is course and the other is year level.  The courses should be MATH, SCIENCE, ..., while the yearlevel should have values of 1, 2, 3 and 4 corresponding to the codes at the right end in the original string variable.  Do somebody know the spss syntax?

Thank you.

John


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: recoding

Norton, John
Try the following:

STRING course (A10).
COMPUTE course = SUBSTR(LTRIM(RTRIM(old_var)),1,INDEX(old_var,'-')-1).
COMPUTE course_year = NUMBER(SUBSTR(old_var,INDEX(oldvar,'-')+1),F8.2).
EXE.

Hope that helps,

John Norton


-----Original Message-----
From: SPSSX(r) Discussion on behalf of John Amora
Sent: Sat 3/15/2008 7:34 PM
To: [hidden email]
Subject:      recoding
 
A string variable has values in the form of course-yearlevel (such as MATH-1, MATH-2, MATH-3, MATH-4,SCIENCE-1,SCIENCE-2,...., et cetera).  I want to split it into two variables where the first is course and the other is year level.  The courses should be MATH, SCIENCE, ..., while the yearlevel should have values of 1, 2, 3 and 4 corresponding to the codes at the right end in the original string variable.  Do somebody know the spss syntax?

Thank you.

John


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: recoding

Bob Walker-2
In reply to this post by Johnny Amora
Hi John,

Assuming that your "Year" values are one character wide:

DATA LIST FREE / COURSEYR (A15).
BEGIN DATA
MATH-1
MATH-2
MATH-3
MATH-4
SCIENCE-1
SCIENCE-2
END DATA.

STRING COURSE(A15).
COMPUTE #K=LENGTH(RTRIM(LTRIM(COURSEYR))).
COMPUTE YEAR=NUMBER(SUBSTR(COURSEYR,#K,1),F2.0).
COMPUTE #J=INDEX(COURSEYR,"-").
COMPUTE COURSE=SUBSTR(COURSEYR,1,#J-1).
EXECUTE.
DATASET NAME File1 WINDOW=FRONT.

Regards,

Bob Walker
Surveys & Forecasts, LLC

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
John Amora
Sent: Saturday, March 15, 2008 8:35 PM
To: [hidden email]
Subject: recoding

A string variable has values in the form of course-yearlevel (such as
MATH-1, MATH-2, MATH-3, MATH-4,SCIENCE-1,SCIENCE-2,...., et cetera).  I want
to split it into two variables where the first is course and the other is
year level.  The courses should be MATH, SCIENCE, ..., while the yearlevel
should have values of 1, 2, 3 and 4 corresponding to the codes at the right
end in the original string variable.  Do somebody know the spss syntax?

Thank you.

John



____________________________________________________________________________
________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
[hidden email] (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