Login

Recoding Variables in SPSS Statistics (cont...)

Introduction to recoding data into two categories in SPSS Statistics

Similar to the previous page, 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 split these into two categories only (e.g., two categories such as exam scores "between 40 and 100", which might be considered a "pass", and exam scores "between 0 and 39", which might be considered a "fail"). To achieve this, you can create a new variable with these new categories (e.g., the two exam categories above), where these new categories are based on a cut-off between two values (e.g., "40 and above" and "39 and below").

In the sections that follow, we start with the example we use to demonstrating how to recode data into two categories, 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 data into two categories 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 data into two categories, 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 data into two categories

In this example, 12 customers rated how satisfied they were with a new product on a scale of 0 to 10, where 0 was the lowest level of satisfaction and 10 was the highest level of satisfaction, as shown below:

Customer satisfaction ratings for a new product
Ratings 3 6 8 9 7 2 10 6 4 8 9 3

In the table above, the scores ranged from "2", the lowest satisfaction rating, to "10", the highest satisfaction rating. We want to recode the data into two categories such that all customers who gave a satisfaction rating of 5 or lower are coded under the new category, "Dissatisfactory", and all customers who gave a satisfaction rating of 6 or greater are coded under the new category, "Satisfactory", as shown below:

Recoding satisfaction ratings into two categories
New categories Dissatisfactory Satisfactory
Satisfaction rating 5 or lower 6 or greater

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 data into two categories instead.

SPSS Statistics

Data setup in SPSS Statistics when recoding data into two categories

To recode data into two categories, 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 are the ratings of the 12 customers, as shown in the Variable View below:

data view with continuous 'scale' variable 'Ratings'

Published with written permission from SPSS Statistics, IBM Corporation.

Our variable, Ratings, is entered on row 1 in the Variable View above. To set up this variable, we gave it the name, "Ratings", under the name column, as well as a label, "Customer satisfaction ratings from 0 to 10", under the label column. In our example, Ratings 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 'ratings'

Published with written permission from SPSS Statistics, IBM Corporation.


Under the runs column of the Data View above, the satisfaction ratings of the new product for each of the 12 customers is entered on a separate row. For example, a satisfaction rating of "3" was entered on row 1, a rating of "6" was entered on row 2, a rating of "8" 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 data into two categories

In this section, we first explain how to use the Recode into Different Values procedure in SPSS Statistics to recode our continuous variable, Ratings, into two categories: "Dissatisfactory" and "Satisfactory". This will create the new string variable, NRatings (i.e., a "string" variable is a variable that consists of text/characters, such as "Dissatisfactory" and "Satisfactory"). Next, we explain how to use the Automatic Recode procedure in SPSS Statistics to convert this string variable, NRatings, into the nominal, NORatings, and finally, the new ordinal variable we are trying to create: NORatings.

Note: Both the Recode into a Different Variables and Automatic Recode procedures are not destructive. Therefore, your existing variable will not be replaced. Instead, new variables will be 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 continuous variable to be recoded, Ratings, into the Numeric Variable -> Output Variable: box, by using the right arrow button. You will end up with the following screen:
    ratings 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, "NRatings", into the Name: box, and then entered a label for our new variable, "New Ratings", 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. This will allow you to create the new string variable: NRatings. You will be presented with an updated Numeric Variable -> Output Variable: box, as shown below:

    Note: By default, SPSS Statistics creates a nominal variable when you use the Recode into a Different Variables procedure (i.e., NORatings). However, since we will be adding characters/text when setting up our two new categories, "Dissatisfactory" and "Satisfactory", in the next step, a string variable will be created instead (i.e., NRatings). Therefore, we explain how to convert this string variable, NRatings, into the nominal variable, NORatings, and finally the ordinal variable, NORatings, later in this guide.

    new variable, 'NRatings', 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.

    Explanation: In this example, we want the "old values" from our variable, Ratings, to be converted into "new values" in our new string variable, NRatings, as shown below:

         Customer satisfaction ratings of 5 or lower (old) become the (new) Dissatisfactory category

         Customer satisfaction ratings of 6 or greater (old) become the (new) Satisfactory category.

  6. Enter "5" into the Range, LOWEST through value: box in the –Old Value– area. Next, click on the Output variables are strings checkbox and enter a value into the Width: box that is one greater than the number of characters of the name of the new category you want to create. For example, we plan to create the new category, "Dissatisfaction", which is 15 characters long. Therefore, we entered "16" into the Width: box (i.e., 15 + 1 = 16). Finally, enter "Dissatisfactory" into the Value: box in the –New Value– area.

    Note: When you create a category using text/characters (e.g., "Dissatisfactory") instead of a number (e.g., "1"), this is called a "string" when it is entered into the Data View of SPSS Statistics. Unfortunately, if you enter a value in the Width: box that is too small (e.g., if we had entered "10" for our category, "Dissatisfactory"), SPSS Statistics will either give you an error or cut part of the text (i.e., it will truncate the text, such that only some of the characters of "Dissatisfactory" would appear, such as "Dissatisf"). If you make a mistake and enter a number that is too small for your text/characters, it is possible to correct this mistake later, but it requires a few extra steps in SPSS Statistics. If you would like us to add a guide to show how to do this, please contact us.

    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 the text, "Dissatisfactory", for the new string variable, NRatings, for any customer satisfaction rating of "5 or lower" in the existing continuous variable, Ratings. This new text, "Dissatisfactory", will be shown in the Data View of SPSS Statistics after completing all the steps that follow.

  8. Enter "6" into the Range, value through HIGHEST: box in the –Old Value– area and enter "Satisfactory" into the Value: box in the –New Value– area, as shown below:

    Note: We kept "16" as the value in the Width: box because the text for the category, "Satisfactory", has fewer characters than the text for the category, "Dissatisfactory", which we entered earlier. However, if our new category had more characters, we would need to increase the value we entered into the Width: box. For example, if the new category had 18 characters, we would enter "19" into the Width: box (i.e., 18 + 1 = 19).

    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 the text, "Satisfactory", for the new string variable, NRatings, for any customer satisfaction rating of "6 or greater" in the existing continuous variable, Ratings. This new text, "Satisfactory", will be shown in the Data View of SPSS Statistics after completing all the steps that follow.

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

  11. Click on the ok button to produce the new string variable, NRatings, which contains the two categories – "Dissatisfactory" and "Satisfactory" – as shown below:

    Note: As mentioned in Step 4 earlier, by default, SPSS Statistics creates a string variable when you select the Output variables are strings checkbox (e.g., in Step 6) and enter text (i.e., a string) into the Value: box in the –New Value– area. In our example, this string variable is NRatings. However, the variable should be ordinal (i.e., NORatings). Therefore, in the next steps, we show you how to use the Automatic Recode procedure in SPSS Statistics to convert the string variable, NRatings, into the nominal variable, NORatings, and finally, the ordinal variable, NORatings (i.e., where we named our new, ordinal variable, "NORatings", to reflect that it is our "New Ordinal Ratings" variable).

    data view with new recoded variable 'NScores'

    Published with written permission from SPSS Statistics, IBM Corporation.

  12. Click on Transform > Automatic Recode... in the main menu, as shown below:
    'automatic recode' menu item displayed

    Published with written permission from SPSS Statistics, IBM Corporation.


    You will be presented with the Automatic Recode dialogue box, as shown below:
    'automatic recode' dialogue box displayed

    Published with written permission from SPSS Statistics, IBM Corporation.

  13. Transfer the string variable to be automatically recoded, NRatings, into the Variable -> New Name: box, by using the right arrow button. You will end up with the following screen:
    'nratings' transferred in 'automatic recode' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

  14. The New Name: box is where you enter a new name for the NRatings variable, which will "eventually" become the new, ordinal variable, NORatings. Therefore, we entered the name, "NORatings", into the New Name: box, to create the new ordinal variable, NORatings, as shown below:

    Note: We state that NRatings will "eventually" become the ordinal variable NORatings because by default, SPSS Statistics creates a nominal variable when you use the Automatic Recode procedure (i.e., NORatings). Therefore, you will need to change the measurement type of your variable from nominal to ordinal in the Variable View, which we show you how to do later.

    new name 'NORatings' entered for 'nratings' in 'automatic recode' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

  15. Click on the add new name button to create this new variable. You will be presented with an updated Variable -> New Name: box, as shown below:
    new variable, 'NORatings', named in 'automatic recode' dialogue box

    Published with written permission from SPSS Statistics, IBM Corporation.

  16. Click on the ok button to produce the new nominal variable: NORatings, as shown under the noratings column below:
    data view with new recoded variable 'NScores'

    Published with written permission from SPSS Statistics, IBM Corporation.

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

    Published with written permission from SPSS Statistics, IBM Corporation.

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

  19. Click on the data view tab, which will become highlighted: data view. You will be presented with the Data View that includes your new ordinal variable, NORatings, under the nratings 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 nratings column, the two categories – "Dissatisfactory" and "Satisfactory" – are displayed for the ordinal variable, NORatings. For example, a customer with a satisfaction rating of "3" along row 1 under the ratings column has been put into the "Dissatisfactory" category under the noratings column to reflect that a satisfaction rating of "3" fits within the "5 or lower" category of the 10-point satisfaction scale, which was coded as "Dissatisfactory". To provide another example, the customer with a satisfaction rating of "6" along row 2 under the ratings column has been put into the "Satisfactory" category under the noratings column to reflect that a satisfaction rating of "6" fits within the "6 or greater" category of the 10-point satisfaction scale, which was coded as "Satisfactory".

    Note: We demonstrate the Automatic Recode procedure for our data set. However, there are different ways to use this procedure depending on your data (e.g., if you have any missing data, the alphabetical order of your categories, illegal characters, etc.). Therefore, we will be adding a guide dedicate to converting string variables into numeric variables that explain these different options. If you would like us to let you know when this guide becomes available, please contact us.

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

SPSS Statistics

Syntax

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

spss syntax required to recode data into two categories

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 data into two categories 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
« prev