Unit 7 · Prepare your data

How to merge files in SPSS: Add Cases and Add Variables

Merge SPSS data files with Add Cases and Add Variables, match participants on an ID key variable, and restructure wide data to long.

Free tutorialPro practiceAbout 5 minutes7 practice questions

Quick answer: How do you merge files in SPSS?

  1. Open the main file, then click Data › Merge Files.
  2. Choose Add Cases for new participants, or Add Variables for new measures on the same people.
  3. For Add Variables, choose one-to-one merge based on key values and select the ID as the key.
  4. Click OK, then check the number of cases.

Last updated November 2026 · Not sure this is the right test? Try the Which statistical test? tool.

Combining data files

Research data often arrives in pieces: a second batch of participants, or follow-up measures for the same people. Merging puts them into one file so you can analyse them together.

When to use it

  • Add Cases: new participants with the same variables (stacking rows).
  • Add Variables: new variables for the same participants (adding columns).
  • Restructure: switching between wide format (one row per person) and long format (one row per measurement).

How it works

Add Variables matches rows on a key variable, such as a participant ID, that exists in both files with the same name and type. People without a match get missing values for the new variables. Variables that appear in both files are excluded from the second file so they don’t overwrite the first. Add Cases matches columns by name, so the same variable needs the same name in both files.

Worked example

A baseline file and a follow-up file both have id. Add Variables (one-to-one, key = id) gives one file with baseline and follow-up scores side by side, ready for a paired t-test.

Key terms

Key variable
An ID that identifies the same case in both files.
Wide format
One row per participant; repeated measures in separate columns.
Long format
One row per measurement.

Common mistakes

  • Duplicate IDs, which create wrong matches.
  • Different names or types for the same variable in the two files.
  • Not checking the case count after merging.

How to do it in SPSS

Add Variables

Data › Merge Files joins two data files. Add Variables puts new columns next to existing people; Add Cases stacks new people under the existing ones.

Add Variables to survey.sav [DataSet1]
Merge Method1
✓One-to-one merge based on key values
One-to-many merge based on key values
One-to-one merge based on file order
Key Variables:2
id
Excluded Variables:3
age(+)
Included Variables:4
id(*)
gender(*)
age(*)
score(*)
anx_post(+)
dep_post(+)
OKPasteResetCancelHelp
  1. 1
    Merge methodOne-to-one on key values matches people by ID, which is safest. Matching by file order only works if both files are in exactly the same order.
  2. 2
    Key variableThe ID that identifies the same person in both files. It needs the same name and type in each file, and every value must be unique.
  3. 3
    Excluded VariablesVariables in both files are excluded from the second file so they don’t overwrite your data.
  4. 4
    (*) and (+)(*) marks variables from the open file, (+) from the file being added. Here the follow-up adds anx_post and dep_post.

Before merging, save a copy of both files. Afterwards, check the number of cases: people in only one file get blanks for the other file’s variables.

The SPSS syntax

Prefer typing to clicking? Open File › New › Syntax, paste this in, select it and choose Run › Selection. Every dialog's Paste button writes the same kind of code.

* Add Variables: both files must be sorted by the key variable.
SORT CASES BY id.
MATCH FILES /FILE=*
  /FILE='C:\Users\you\Documents\followup.sav'
  /BY id.
EXECUTE.

* Add Cases: stack new participants underneath.
ADD FILES /FILE=*
  /FILE='C:\Users\you\Documents\batch2.sav'.
EXECUTE.

Practice data

Download the file used in this lesson and run it yourself in SPSS: you should get the same results as the screens above.

  • survey.savMain survey file to merge into (N = 40)
  • followup.savFollow-up measures for the same participants (Add Variables)
  • batch2.savA second batch of participants (Add Cases)

Now practise it interactively →

Reading is only half of it. Tap through the real SPSS menus, read the output and pick the right write-up in 7 quick questions, with instant feedback on every answer.

Practice for this lesson is part of Pro, with every unit, unlimited hearts and saved progress.

More in Prepare your data