Login

Recoding Variables in SPSS Statistics (cont...)

Introduction to recoding a given range of values in SPSS Statistics

You can group/categorize values in a dataset using a range of values. For example, you may have individual values in your data set (e.g., salaries in US dollars, exam scores from 0 to 100, cholesterol concentration measured in mmol/L) and you want to group these into a number of categories (e.g., four salary "bands", such as salaries "under $20,000", salaries "between $20,001 and $50,000", salaries "between $50,001 and $100,000", and salaries "over $100,000"). To achieve this, you can create a new variable with these new categories (e.g., the four salary ranges above), where these new categories are based on a range of values within your existing variable (e.g., salaries such as "$21,596", "$27,500" and "$29,999" would be included in the new category, salaries "between $20,001 and $50,000").

In the sections that follow, we start with the example we use to demonstrating how to recode a given range of values, 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 given range of values 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 given range of values, 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 a given range of values

In this example, the scores of 10 students in an exam were recorded on a scale of 0 to 100 marks, as shown below:

Examination scores of 10 students
Scores 58 86 74 70 79 60 35 42 55 91

In the table above, the scores ranged from "35", the lowest score, to "91", the highest score. We want to recode the data into the following ranges:

Recoding examination scores into ranges
New coding 1 2 3 4
Exam scores between 75-100 61-74 41-60 0-40

In the table above, a code of "1" will be given to exam scores "between 75 and 100" (i.e., "1" = "75-100"), a code of "2" will be given to exam scores "between 61 and 74" (i.e., "2" = "61-74"), a code of "3" will be given to exam scores "between 41 and 60" (i.e., "3" = "41-60") and a code of "4" will be given to exam scores "between 0 to 40" (i.e., "4" = "0-40").

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 a given range instead.

SPSS Statistics

Data setup in SPSS Statistics when recoding a given range of values

To recode a given range of 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 exam scores of the 10 students, as shown in the Variable View below:

data view with continuous 'scale' variable 'Scores'

Published with written permission from SPSS Statistics, IBM Corporation.


Our variable, Scores, is entered on row 1 in the Variable View above. To set up this variable, we gave it the name, "Score", under the name column, as well as a label, "Exam scores from 0 to 100", under the label column. In our example, Scores 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, Scores

Published with written permission from SPSS Statistics, IBM Corporation.


Under the runs column of the Data View above, the exam score for each of the 10 students is entered on a separate row. For example, the score of "58" was entered on row 1, the score of "86" was entered on row 2, the score of "74" was entered on row 3, and so forth. Since these cells will initially be empty, you need to click into the cells to enter your data.

Testimonials
TAKE THE TOUR


SPSS Statistics

SPSS Statistics procedure to recode a given range of values

In this section, we explain how to use the Recode into a Different Variables procedure in SPSS Statistics to recode our variable, Scores, into a given range of values. This will create the new variable: NScores.

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, Scores, into the Numeric Variable -> Output Variable: box, by using the right arrow button. You will end up with the following screen:
    scores 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, "NScores", into the Name: box, to create the new variable, NScores, and then entered a label for our new variable, "New Scores", as shown below:
    Scores 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, Scores, to be converted into "new values" in our new variable, NScores, as shown below:

    Exam scores between 75 and 100 (old) become 1 (new)

    Exam scores between 61 to 74 (old) become 2 (new)

    Exam scores between 41 to 60 (old) become 3 (new)

    Exam scores between 0 to 40 (old) become 4 (new)

  6. Enter the first range of values, "75 to 100", into the Range: box within the –Old Value– area, and set the new code to "1" into the Value: box within the –New Value– area, as shown below:
    first category - '75 to 100' 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 - '75 to 100' 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, NScores, for any values "between 75 and 100" in the existing variable, Scores. 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 the second range of values, "61 to 74", into the Range: box within the –Old Value– area, and set the new code to "2" into the Value: box within 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 - '61 to 74' 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, NScores, for any values "between 61 and 74" in the existing variable, Scores.

  10. Enter the third range of values, "41 to 60", into the Range: box within the –Old Value– area, and set the new code to "3" into the Value: box within the –New Value– area, as shown below:
    third category - '41 to 60' 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 - '41 to 60' 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, NScores, for any values "between 41 and 60" in the existing variable, Scores.

  12. Enter the first range of values, "0 to 40", into the Range: box within the –Old Value– area, and set the new code to "4" into the Value: box within the –New Value– area, as shown below:
    fourth category - '0 to 40' 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 - '0 to 40' 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, NScores, for any values "between 0 and 40" in the existing variable, Scores.

  14. 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.

  15. Click on the ok button to produce the new variable containing the recoded values: NScores.
    data view with new recoded variable 'NScores'

    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., NScores). However, the variable should be ordinal (i.e., NScores). 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.

  16. 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, NScores, as highlighted below:
    variable view with new 'ordinal' recoded variable 'NScores' highlighted

    Published with written permission from SPSS Statistics, IBM Corporation.

  17. Change the measurement type of your variable from nominal to ordinal under the measure column to reflect that the new, ranked ordered variable, NScores, 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, NScores, is highlighted below:
    variable view with new 'ordinal' recoded variable 'NScores' 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.

  18. 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, NScores, under the nscores column, as shown below:
    data view with new recoded variable 'NScores' having been changed to 'ordinal

    Published with written permission from SPSS Statistics, IBM Corporation.

    Explanation: Under the nscores column, the new ranges are displayed for the variable, Scores. For example, the student with an exam score of "58" along row 1 under the scores column has been given a value of "3" under the nscores column to reflect that a score of "58" is "between 41 and 60", which was coded as "3". To provide another example, the student with an exam score of "86" along row 2 under the scores column has been given a value of "1" under the nscores column to reflect that a score of "86" is "between 75 and 100", which was coded as "1".

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

SPSS Statistics

Syntax to recode a given range of values

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

spss syntax required to recode a given range of  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 a given range of 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
« prevnext »