Login

Recoding Variables in SPSS Statistics

Introduction

The instructions on the following three pages show you how to recode variables using the Recode into a Different Variables procedure in SPSS Statistics. It is also possible to recode variables using a different procedure in SPSS Statistics, which is the Recode into Same Variables procedure. If you would like us to demonstrate this procedure, please contact us and we will add another guide to help.

Over the following three pages, we illustrate three main types of recoding: (a) recoding single or multiple values; (b) recoding a given range of values; and (c) recoding data into two categories. These are briefly explained in the bullets below and then covered in more detail over the following three pages:

Note: If we do not cover the type of recoding you are trying to carry out, please contact us, providing a description of what you are trying to do. We may already have another SPSS Statistics guide to help in our website.

Testimonials
TAKE THE TOUR


SPSS Statistics

Introduction to recoding single or multiple values in SPSS Statistics

There are many different reasons why you may want to create a new value (e.g., "1") to represent an old value (e.g., "120"). You can do this for one value or multiple values at the same time. In our example, we show you have to do this for multiple values, but the procedure is the same for one value.

In the sections that follow, we start with the example we use to demonstrating how to recode a single value, before showing you how to set up your data in the Variable View and Data View of SPSS Statistics. Next, we set out the SPSS Statistics procedure to recode a single value using our example, which also illustrates how the new variable will appear in the Variable View and Data View of SPSS Statistics. Finally, we show the syntax that is run by SPSS Statistics to recode a single value, just in case you prefer to use syntax (i.e., code) rather than the graphical user interface (GUI) when working with SPSS Statistics.

Note: If we do not cover the type of recoding you are trying to carry out, please contact us, providing a description of what you are trying to do. We may already have another SPSS Statistics guide to help in our website.

SPSS Statistics

Example used to recode single or multiple values

In this example, the number of runs scored by five batsman in a game of cricket were recorded, as shown below:

  Number of runs by batsmen
Batsmen 1 2 3 4 5
Runs 86 120 56 10 18

In the table above, the scores for each batsman are recorded as the cricket match took place. Therefore, the first batsman to compete in the cricket match scored 86 runs (i.e., Batsman 1 above), the second batsman scored 120 runs (Batsman 2), the third batsman scored 56 runs (Batsman 3), and so forth.

When the cricket match finished, we wanted to recode the data so that the batsmen were rank ordered by their number of runs. Therefore, we wanted the batsman with the highest number of runs to be given a ranking of "1" and the batsman with the lowest number of runs to be given a ranking of "5", as shown below:

  Number of runs by batsmen
Rank ordered 1 2 3 4 5
Runs 120 86 56 18 10

In the table above, a code of "1" was given to the batsman with the highest number of runs, which was "120" (i.e., "1" = "120"), a code of "2" was given to the batsman with the second highest number of runs, which was "86" (i.e., "2" = "86"), and so forth, such that a code of "5" was given to the batsman with the lowest number of runs, which was "10" (i.e., "5" = "10").

In the next section, we explain how to set up this data in SPSS Statistics. However, if you already know how to correctly set up your data in SPSS Statistics, you can skip this section and go to the SPSS Statistics procedure to recode your values instead.

SPSS Statistics

Data setup in SPSS Statistics when recoding single values

To recode single or multiple values, you first have to set up your data using the Variable View and Data View in SPSS Statistics. The Variable View is where you define the types of variables you have and the Data View is where you enter your data for these variables. In this example, there is only one variable, which is the number of runs scored by each batsman, as shown in the Variable View below:

data view with continuous 'scale' variable 'Runs'

Published with written permission from SPSS Statistics, IBM Corporation.


Our variable, Runs, is entered on row 1 in the Variable View above. To set up this variable, we gave it the name, "Runs", under the name column, as well as a label, "Number of runs scored by each batsman", under the label column. In our example, Runs is a continuous variable, so we selected scale under the measure column. As a result, the Data View will look as follows:

data view with continuous 'scale' variable 'Runs'

Published with written permission from SPSS Statistics, IBM Corporation.


Under the runs column of the Data View above, the number of runs scored by each batsman is entered on a separate row. For example, "86" was entered on row 1 to reflect the 86 runs scored by Batsman 1, "120" was entered on row 2 to reflect the 120 runs scored by Batsman 2, "56" was entered on row 3 to reflect the 56 runs scored by Batsman 3, and so forth. Since these cells will initially be empty, you need to click into the cells to enter your data.

SPSS Statistics

SPSS Statistics procedure to recode single or multiple values

In this section, we explain how to use the Recode into Different Values procedure in SPSS Statistics to recode our variable, Runs, so that the values are ranked ordered. This will create the new variable: RankedRuns.

Note: The Recode into a Different Variables procedure is not destructive. Therefore, your existing variable will not be replaced. Instead, a new variable is created.

  1. Click on Transform > Recode into Different Variables... in the main menu, as shown below:
    'recode into different variables' menu item displayed

    Published with written permission from SPSS Statistics, IBM Corporation.


    You will be presented with the Recode into Different Variables dialogue box, as shown below:
    'recode into different variables' dialogue box displayed

    Published with written permission from SPSS Statistics, IBM Corporation.

  2. Transfer the variable to be recoded, Runs, into the Numeric Variable -> Output Variable: box, by using the right arrow button. You will end up with the following screen:
    runs transferred in 'recode into different variables' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

    Note: You will notice that the –Output Variable– area is no longer "greyed out", and neither is the old and new values button.

  3. The –Output Variable– area is where you enter the name and label of the new variable you want to create. Therefore, we entered the name, "RankedRuns", into the Name: box, to create the new variable, RankedRuns, and then entered a label for our new variable, "Ranked Runs", as shown below:
    Runs named and labels in 'recode into different variables' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

  4. Click on the change button to create this new variable. You will be presented with an updated Numeric Variable -> Output Variable: box, as shown below:
    new variable, 'RankedRuns', named and labelled in 'recode into different variables' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

  5. Click on the old and new values button and you will be presented with the Recode into Different Variables: Old and New Values dialogue box, as shown below:
    'recode into different variables: old and new values' dialogue box displayed

    Published with written permission from SPSS Statistics, IBM Corporation.


    In this example, we want the "old values" from our variable, Runs, to be converted into "new values" in our new variable, RankedRuns, as shown below:

    120 (old) becomes 1 (new)

    86 (old) becomes 2 (new)

    56 (old) becomes 3 (new)

    18 (old) becomes 4 (new)

    10 (old) becomes 5 (new)

  6. Enter "120" into the Value: box in the –Old Value– area and enter "1" into the Value: box in the –New Value– area, as shown below:
    first category - '120' and '1' - entered

    Published with written permission from SPSS Statistics, IBM Corporation.

  7. Click on the add button. This will commit the changes and you will see a new entry in the Old --> New: box reflecting this particular recoding, as shown below:
    first category - '120' and '1' - added

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: This instructs SPSS Statistics to add a value of "1" for the new variable, RankedRuns, whenever there is a value of "120" in the existing variable, Runs. This new value of "1" will be shown in the Data View of SPSS Statistics after completing all the steps that follow.

    Note: In the steps that follow, you will repeat the process above for the other values that need recoding so that you end up with the following screen:

    complete setup for all categories displayed

    You can see all the recoding instructions in the Old --> New: box above.

  8. Enter "86" into the Value: box in the –Old Value– area and enter "2" into the Value: box in the –New Value– area, as shown below:
    second category - '86' and '2' - entered

    Published with written permission from SPSS Statistics, IBM Corporation.

  9. Click on the add button. This will commit the changes and you will see a new entry in the Old -->New: box reflecting this particular recoding, as shown below:
    second category - '86' and '2' - added

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: This instructs SPSS Statistics to add a value of "2" for the new variable, RankedRuns, whenever there is a value of "86" in the existing variable, Runs.

  10. Enter "56" into the Value: box in the –Old Value– area and enter "3" into the Value: box in the –New Value– area, as shown below:
    third category - '56' and '3' - entered

    Published with written permission from SPSS Statistics, IBM Corporation.

  11. Click on the add button. This will commit the changes and you will see a new entry in the Old --> New: box reflecting this particular recoding, as shown below:
    third category - '56' and '3' - added

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: This instructs SPSS Statistics to add a value of "3" for the new variable, RankedRuns, whenever there is a value of "56" in the existing variable, Runs.

  12. Enter "18" into the Value: box in the –Old Value– area and enter "4" into the Value: box in the –New Value– area, as shown below:
    fourth category - '18' and '4' - entered

    Published with written permission from SPSS Statistics, IBM Corporation.

  13. Click on the add button. This will commit the changes and you will see a new entry in the Old --> New: box reflecting this particular recoding, as shown below:
    fourth category - '18' and '4' - added

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: This instructs SPSS Statistics to add a value of "4" for the new variable, RankedRuns, whenever there is a value of "18" in the existing variable, Runs.

  14. Enter "10" into the Value: box in the –Old Value– area and enter "5" into the Value: box in the –New Value– area, as shown below:
    fifth category - '10' and '5' - entered

    Published with written permission from SPSS Statistics, IBM Corporation.

  15. Click on the add button. This will commit the changes and you will see a new entry in the Old --> New: box reflecting this particular recoding, as shown below:
    fifth category - '10' and '5' - added

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: This instructs SPSS Statistics to add a value of "5" for the new variable, RankedRuns, whenever there is a value of "10" in the existing variable, Runs.

  16. Click on the continue button and you will be returned to the Recode into Different Variables dialogue box, as shown below:
    all categories set up ready to be coded

    Published with written permission from SPSS Statistics, IBM Corporation.

  17. Click on the ok button to produce the new variable containing the recoded values, RankedRuns, as shown below:
    data view with new recoded variable 'RankedRuns'

    Published with written permission from SPSS Statistics, IBM Corporation.

    Note: By default, SPSS Statistics creates a nominal variable when you use the Recode into a Different Variables procedure (i.e., RankedRuns). However, the variable should be ordinal (i.e., RankedRuns). Therefore, you need to change the measurement type of your variable from nominal to ordinal in the Variable View. We show you how to do this in the next step.

  18. Click on the variable view tab, which will become highlighted: variable view. You will be presented with the Variable View that includes your new variable, RankedRuns, as highlighted below:
    variable view with new 'ordinal' recoded variable 'RankedRuns' highlighted

    Published with written permission from SPSS Statistics, IBM Corporation.

  19. Change the measurement type of your variable from nominal to ordinal under the measure column to reflect that the new, ranked ordered variable, RankedRuns, is an ordinal variable. Next, change the number of decimal places from the default, "2", to "0", under the decimals column. The setup for your new variable, RankedRuns, is highlighted below:
    variable view with new 'ordinal' recoded variable 'RankedRuns' highlighted

    Published with written permission from SPSS Statistics, IBM Corporation.

    Note: For consistency, we also changed the cell under the role column from input to input and changed the alignment from right to right under the align column.

  20. Click on the data view tab, which will become highlighted: data view. You will be presented with the Data View that includes your new variable, RankedRuns, under the rankedruns column, as shown below:
    data view with new recoded variable 'RankedRuns' having been changed to 'ordinal

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: Under the rankedruns column in the Data View above, the new ordered ranks are displayed for the variable, Runs. For example, the batsman with the highest number of runs, "120", along row 2 under the runs column has been given a value of "1" under the rankedruns column (i.e., "120" = "1"). As another example, the batsman with the lowest number of runs, "10", along row 4 under the runs column, has been given a value of "5" under the rankedruns column (i.e., "10" = "5").

You have now successfully recoded your values. In the next section, we shown how to use syntax to recode multiple values.

SPSS Statistics

Syntax to recode single values

You can also use syntax and the Syntax Editor in SPSS Statistics to recode single or multiple values rather than the graphical user interface (GUI) we illustrated in this guide. To illustrate this, the syntax for recoding multiple values for the example in this guide is shown below:

spss syntax required to recode single or multiple values

Published with written permission from SPSS Statistics, IBM Corporation.


Note: If you would like us to explain each part of the syntax above, please contact us and we will add a new section to help.

Referencing

Laerd Statistics (2025). Recoding single or multiple values in SPSS Statistics. Statistical tutorials and software guides. Retrieved from https://statistics.laerd.com/

Join the 10,000s of students, academics and professionals who rely on Laerd Statistics.TAKE THE TOUR
next »