## Recode Multiple variables

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Keerthyv
Posts: 5
Joined: Mon Jul 13, 2015 9:42 pm

### Recode Multiple variables

Hi..

Iam a beginner for Spss..

I was trying to recoding multiple variables
below is the recode i have written - numerical

Recode Q2_1_2 To Q2_79_2
(1 thru 9=1)
(10 thru 19=2)
(20 thru 29=3)
(30 thru 39=4)
(40 thru 49=5)
(50 thru 59=6)
(60 thru 69=7)
(70 thru 79=8)
(80 thru 89=9)
(90 thru 99=10)
(100=11) INTO Q2R_1_2 THRU Q2R_79_2.

Correct the syntax wherever is needed..

Keerthyv
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

### Re: Recode Multiple variables

Good question - or is it an order ("correct...")? Anyway, a great tutorial with well written examples is http://www.spss-tutorials.com/spss-recode-command/

The main problem is in the spec of your new variables: when defining new variables with TO, you can only vary the last subscript. That is,

Code: Select all

``V1_1 TO V5_5``
is not valid, but

Code: Select all

``V1_1 TO V1_25``
is. I further suggest you take a look at this excellent explanation of the TO keyword: http://www.spss-tutorials.com/spss-keywords/#to.

Second, use TO for ranges of variables, THRU for ranges of values.

Third, perhaps put the entire command on one or two lines, it'll keep your syntax more compact.

Fourth, are you sure there's only integer values in these variables? Note that 9.5 will not be RECODEd into anything.

Fifth, you consider using

Code: Select all

``compute newvar = trunc(oldvar/ 10) + 1.``
in a DO REPEAT block instead of RECODE here.
Keerthyv
Posts: 5
Joined: Mon Jul 13, 2015 9:42 pm

### Re: Recode Multiple variables

Rubeen thank u...

It is v1_1 to v1_25.. No decimals like 9.5..
It is range of variables..

Could you provide me a working /updated spec to work with..

I already gone through tutorials.. I don't find multiple variable recoding...
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

### Re: Recode Multiple variables

If you didn't find multiple variable recoding, then you didn't read my suggestion: http://www.spss-tutorials.com/spss-recode-command/.

Section 2 is literally called "2. Dichotomize Multiple Variables". After two lines you find a working spec:

Code: Select all

``recode v4 to v6 (1,2,3 = 0)(4,5 = 1).``
I don't see anything in your question that doesn't get a clear and concise answer in the tutorials I proposed. Perhaps put a little more effort into it.
Keerthyv
Posts: 5
Joined: Mon Jul 13, 2015 9:42 pm

### Re: Recode Multiple variables

Rubeen..

If possible could you rewrite the code correctly for me.. instead of providing links..

i Had recode variables without TO or INTO for the same... like
Recode var1 var2..Var79..
.
.
.
.
. into Var11 var12 var13..Var179.

Could you rewrite the correct code for me..

If u still feel there is no concise & clear QUestion in mine.. i have to think to move this thread from beginner section for best solution.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: Recode Multiple variables

also, the questions you ask are clearly explained in Rubens files, so it is not clear what you want help with.
Keerthyv
Posts: 5
Joined: Mon Jul 13, 2015 9:42 pm

### Re: Recode Multiple variables

GerineL..
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: Recode Multiple variables

I sense some sarcasm. again, if you need help, indicate what you have done, what goes wrong, and what you want to achieve.
Keerthyv
Posts: 5
Joined: Mon Jul 13, 2015 9:42 pm

### Re: Recode Multiple variables

It was not sarcasm...

To reiterate..

My code is

Recode Var1 to Var79
(1thru 2)
.
.
.
(5thru7)
Into Var1R to Va79R.

I expected a a rewritten / corrected code..but i could see only references posted.."refer this"..."do this"..

I said i have already googled all those.. also i have read the help index in spss too for the same.. but still i get "refer this".. u say my tone is not good...

Arey it was whole hearted Please bro...u call it sarcasm......
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: Recode Multiple variables

the problem probably is with your "to".

variable X1 to x10 only works if the variable name ends with a number that goes up (e.g., q1 q2 q3 etc)

In your original post you say
Q2_1_2 To Q2_79_2
That doesn't work, because it ends with _2 instead of a number that goes up .

same goes for:
Q2R_1_2 THRU Q2R_79_2
ends with _2 so doesn't work.

So you either need to choose different variable names, or you need to copy/paste the actual variable names instead of using "to".

p.s.
not a dude

### Who is online

Users browsing this forum: No registered users and 4 guests