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.
Quick answer: How do you merge files in SPSS?
- Open the main file, then click Data › Merge Files.
- Choose Add Cases for new participants, or Add Variables for new measures on the same people.
- For Add Variables, choose one-to-one merge based on key values and select the ID as the key.
- Click OK, then check the number of cases.
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
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.