How to use the loop syntax to recode?

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

How to use the loop syntax to recode?

Jung
Hello all,

I have a situation in which I have a series of ID (1 to 3000) variables that I want to use to compute a new series of numeric variables.
I want to recode 1-100  to 1,101-200 to 2,201-300 to 3,etc.

RECODE ID(1 thru 200=1) into order.
EXECUTE.

How to use the loop syntax to convert ?
thanks.
Reply | Threaded
Open this post in threaded view
|

Re: How to use the loop syntax to recode?

Andy W
Note that if you divide by 100, the values will be

1/100 = .01
2/100 = .02
.
.
.
101/100 = 1.01
.
.
201/100 = 2.01

If you truncate the values to the nearest integer you will then have

TRUNC(1/100) = 0
TRUNC(2/100) = 0
.
.
.
TRUNC(101/100) = 1
.
.
TRUNC(201/100) = 2

Subsequently to get your index to start at 1 you just need to add 1 to the result above. An example of this is below.

****************************************.
*making values 1 to 1000.
input program.
loop x = 1 to 1000.
end case.
end loop.
end file.
end input program.
*making recoded value.
compute xRec = TRUNC(x/100) + 1.
exe.
*checking outresults.
DO IF MOD(x,100) = 0 OR MOD(x,100) = 1.
PRINT  /x XRec.
END IF.
EXE.
****************************************.


 
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: How to use the loop syntax to recode?

Andy W
In reply to this post by Jung
Whoops I see you wanted 100 to equal 1 and 200 to equal 2 etc. My advice still applies, just subtract 1 from the Id variable and then divide by 100 and truncate.

Compute IdRec = TRUNC((ID - 1)/100) + 1.

Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: How to use the loop syntax to recode?

David Marso
Administrator
In reply to this post by Jung
Sorry, you have not provided a coherent question.
Please try again with more specifics.
--
Jung wrote
Hello all,

I have a situation in which I have a series of ID (1 to 3000) variables that I want to use to compute a new series of numeric variables.
I want to recode 1-100  to 1,101-200 to 2,201-300 to 3,etc.

RECODE ID(1 thru 200=1) into order.
EXECUTE.

How to use the loop syntax to convert ?
thanks.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: How to use the loop syntax to recode?

Rick Oliver-3
In reply to this post by Jung
*sample data.
data list free /id.
begin data
101 200 201 202 300 222 401 400 499
end data.
*end sample data.
compute #temp=mod(id, 100).
compute order=trunc(id/100).
if #temp=0 order=order-1.
list.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Jung <[hidden email]>
To:        [hidden email],
Date:        01/21/2014 10:31 AM
Subject:        How to use the loop syntax to recode?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello all,

I have a situation in which I have a series of ID (1 to 3000) variables that
I want to use to compute a new series of numeric variables.
I want to recode 1-100  to 1,101-200 to 2,201-300 to 3,etc.

RECODE ID(1 thru 200=1) into order.
EXECUTE.

How to use the loop syntax to convert ?
thanks.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/How-to-use-the-loop-syntax-to-recode-tp5724036.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: How to use the loop syntax to recode?

Jung
In reply to this post by Andy W
Hi! Andy W

I have solved the problem.
I am appreciated greatly your help.

 Jung