
In SPSS, I don't like to recode variables into new variables: the new variables don't have any dictionary information such as variable/value labels or formats. Second, a recoded variable is appended to the end of the file but I rather have it in its original position.
Both problems are avoided by recoding into the same variables. However, I do like to compare the old and new values to see if everything went right. An easy way for doing so is first cloning a variable and then recoding the original variable into the same variable. The clone now serves as a backup to which I can compare the recoded result.
This tutorial presents a super easy tool for cloning one or many variables. It copies variables’ values plus all dictionary information (such as variable labels, value labels, user missing values and formats) from the original variables to the copies. Hence, it really “clones” variables except for their names. Give it a try. You'll love it.
How Does It Work?
- First, make sure you have the SPSS Python Essentials installed.
- Next, download and install the SPSS Clone Variables Tool. Note that this is an SPSS Extension Bundle.
- Open some data and navigate to
.
- Specify the variables you'd like to clone and some prefix: the names for the cloned variables will consist of this prefix plus the original variable names. Click syntax. and run the pasted
- Clones of the variables you specified are now created in the active dataset.
- Clicking the tool's button will take you to this tutorial.
SPSS Clone Variables - Example 1
Those who want to give it a quick shot can download and open freelancers.sav. For cloning the first variable, id, we simply enter it into the first box.

We'll leave the second box unaltered. Now, clicking SPSSTUTORIALS CLONE VARIABLES VARIABLES ='id' PREFIX ='copy_'. Upon running this line of syntax, a new variable called copy_id appears in our data. Except for its name, it's an exact clone of its original counterpart, including its variable label.
results in
SPSS Clone Variables - Example 2
Now let's clone the next two variables, gender and birthday. We can now copy-paste the line of syntax we just pasted and simply change it to SPSSTUTORIALS CLONE VARIABLES VARIABLES ='gender birthday' PREFIX ='copy_'. After running it, note that copy_birthday is a date variable just like its original counterpart.
SPSS Clone Variables - Example 3
Finally, we can clone an entire section of variables by using SPSS’ TO keyword. For instance, we can clone source_2010 through source_2014 by running SPSSTUTORIALS CLONE VARIABLES VARIABLES = 'source_2010 to source_2014' PREFIX ='copy_'.
It's as easy as that. I hope you'll like this tool as much as I do.
Thanks for reading!
THIS TUTORIAL HAS 18 COMMENTS:
By Ruben Geert van den Berg on June 29th, 2019
Hi Daniel, thanks for your comment!
First off, if you're still using SPSS macros, you're going to love Python for SPSS. It's like moving from the menu to syntax: you'll wonder what on earth you've been wasting your time on...
Second, nice thing about numeric suffixes is that they allow for stuff like
RECODE att_04 to att_12 (LO THRU 6 = 0)(ELSE = 1) INTO datt_04 to datt_12.
in which the second variable spec are all new variables. This'll only work if the new variables end with numeric suffixes: att_04d to att_12d wouldn't do the job.
Best regards from Amsterdam!
Ruben
By Claudio on June 30th, 2020
I like that tool - could you update it to Python 3 as IBM stopped supporting Python 2?
By Ruben Geert van den Berg on July 1st, 2020
Hi Claudio!
Yeah, we should. However, I'm probably not going to find the time for it any time soon.
Note, however, that you can still use Python2.x: you can install Python 2.7.15 and then link it with SPSS via Edit - Options - File locations.
Hope that helps!
Ruben
SPSS tutorials