Some SPSS commands such as RECODE and ALTER TYPE can make irreversible changes to variables. Before using these, I like to clone the variables that I'm about to edit. This allows me to compare the edited to the original versions.
This tutorial presents a super easy tool for making exact clones of variables in SPSS. We'll use bank-clean.sav (partly shown below) for all examples.

Prerequisites & Installation
Installing this tool requires
- SPSS version 24 or higher with
- the SPSS Python 3 essentials installed.
Recent SPSS versions usually meet these requirements.
Download our tool from SPSS_TUTORIALS_CLONE_VARIABLES.spe. You can install it from
as shown below.

After completing these steps, you'll find SPSS tutorials - Clone Variables under Transform.

Clone Variables Example I
Let's first clone jtype -short for job type- as illustrated below.

Completing these steps results in the SPSS syntax below. Let's run it.
SPSS_TUTORIALS_CLONE_VARIABLES VARIABLES=jtype
/OPTIONS FIX="c" FIXTYPE=PREFIX ACTION=RUN.
Result
Note that SPSS has now added a new variable to our data: cjtype as shown below.

Except for its name, cjtype is an exact clone of jtype: it has the same
- variable type and format;
- value labels;
- user missing values;
- and so on...
There's one minor issue with our first example: the syntax we just pasted only runs on SPSS installations with our tool installed.
The solution for this is to have the tool print native syntax instead: this syntax is typically (much) longer but it does run on any SPSS installation. Our second examples illustrates how to do just that.
Clone Variables Example II
Let's create native syntax for cloning a couple of different variables, including a string variable and a date variable.

This option has our tool print native syntax into our output window.
Because we chose to print (rather than run) syntax, this is one of the rare occasions at which we click Ok instead of Paste.
Result
Note that we now have native syntax for cloning several variables in our output window.

For actually running this syntax, we can simply copy-paste-run it in a syntax window.The entire syntax is shown below.
STRING clast_name (A30).
RECODE last_name (ELSE = COPY) INTO clast_name.
APPLY DICTIONARY FROM * /SOURCE VARIABLES = last_name /TARGET VARIABLES = clast_name.
RECODE gender (ELSE = COPY) INTO cgender.
APPLY DICTIONARY FROM * /SOURCE VARIABLES = gender /TARGET VARIABLES = cgender.
RECODE dob (ELSE = COPY) INTO cdob.
APPLY DICTIONARY FROM * /SOURCE VARIABLES = dob /TARGET VARIABLES = cdob.
RECODE educ (ELSE = COPY) INTO ceduc.
APPLY DICTIONARY FROM * /SOURCE VARIABLES = educ /TARGET VARIABLES = ceduc.
If our tool creates very long syntax, you could copy it into a separate file and run it from an INSERT command.
Right, I guess that should cover this simple but handy little tool. Hope you'll give it a try and hope you'll find it helpful. If you've any remarks, feel free to throw me a quick comment below.
Thanks for reading!
THIS TUTORIAL HAS 40 COMMENTS:
By Ruben Geert van den Berg on February 5th, 2016
Hi max! You're right. I assumed you didn't have any string variables. But why not try the syntax below? It uses employees.sav.
SPSSTUTORIALS CLONE VARIABLES VARIABLES ='all' PREFIX ='lag_'.
do repeat #old = resp_id to job_satisfaction / #new = lag_resp_id to lag_job_satisfaction.
compute #new = lag(#old).
end repeat.
execute.
Alternatively, you could modify the previous syntax in order to declare new string variables when necessary. But I like the first solution more.
begin program.
import spss
for ind in range(spss.GetVariableCount()):
varnam = spss.GetVariableName(ind)
if spss.GetVariableType(ind) > 0:
spss.Submit('string %s (A16).' %('lag_' + varnam))
spss.Submit('compute %s = lag(%s).'%('lag_' + varnam,varnam))
end program.
execute.
By Max on February 10th, 2016
Thank you so much for all your replies!
I need a "dynamic" script (for variable sets of different sizes), so all solutions using "TO" don't really work.
I tried the last python code but it only produced errors, I guess something is missing. How is "print" supposed to work? I'm curious!
I came up with something different. I modified the code, using "if" now, which seems to work fine:
begin program.
import spss
for ind in range(spss.GetVariableCount()):
varnam = spss.GetVariableName(ind)
if spss.GetVariableType(ind) > 0:
spss.Submit('string %s (A16).' %('lag_' + varnam))
spss.Submit('compute %s = lag(%s).'%('lag_' + varnam,varnam))
end program.
execute.
By Ruben Geert van den Berg on February 11th, 2016
You're right, I guess a typo sneaked into the previous syntax.
Anyway, your syntax should work for all datasets, no matter how many variables or which variable names.
A second option (nicer) is to use the CLONEVARIABLES tool with the ALL instead of the TO keyword. Note that the dialog itself very explicitly suggests you use either keyword -it does so for a reason.
By Catherine on August 29th, 2016
Hi Ruben,
I currently work with SPSS and I am struggling for a while with a variable. I can neither recode nor select its labels. For example, the variable "SEXE" has two modalities, "F" or "M", that appear when I make a distribution of it, but that disappear when I look in the database to display the labels. Do you know how I could create a new variable with this old one without have to make a recode (since the labels F and M are not recognized by SPSS) ? Thanks for the help!
By Ruben Geert van den Berg on August 29th, 2016
Hi Catherine! I don't entirely understand your question. Is SEXE a string variable
or a value labeled numeric variable? If you're not sure what that means in the first place, perhaps read SPSS Variable Types and Formats.
In the second case, you may want to experiment with SET TNUMBERS.
P.s. you can RECODE both string and numeric variables.