SPSS Tutorials



MATCH FILES is an SPSS command mostly used for merging data holding similar cases but different variables. For different cases but similar variables, use ADD FILES. MATCH FILES is also the way to go for a table lookup similar to VLOOKUP in Excel.

SPSS Match FilesMerging two datasets by id, which is a unique case identifier.

SPSS Match Files - Basic Use

SPSS Match Files Syntax Example 1

*1. Create test data 1.

data list free/id test_1.
begin data
3 8 4 5 6 6
end data.
dataset name test_1.

*2. Create test data 2.

data list free/id test_2.
begin data
1 4 3 9 4 8
end data.
dataset name test_2.

*3. Match test_1 and test_2.

match files file = test_1 / file = test_2
/by id.

*4. Close all but merged dataset.

dataset close test_1.
dataset close test_2.

SPSS Match Files - Table

SPSS Match Files Syntax Example 2

*1. Table holding zip codes and cities.

data list free/zip_code (f3.0) city(a20).
begin data
123 'Amsterdam' 456 'Haarlem' 789 "'s Hertogenbosch"
end data.
dataset name cities.

*2. Mini data holding respondents and their zip codes.

data list free /id zip_code.
begin data
1 123 2 123 3 123 4 456 5 456 6 456 7 789 8 789 9 789
end data.

*3. Add cities to active dataset using zip_code.

match files file * / table cities
/by zip_code.

*4. Close all but merged data.

dataset close cities.

SPSS Match Files - One Data Source

SPSS Match Files Syntax Example 3

*1. Single case test data with wrong variable order.

data list free / v1 to v3 v5 v6 v7 v8 v4.
begin data
0 0 0 0 0 0 0 0
end data.

* 2. Reorder variables. Note the TO and ALL keywords here.

match file file * / keep v1 to v3 v4 all.

SPSS Match Files - Rules

Previous tutorial: SPSS RTRIM Function

Next tutorial: SPSS ADD FILES Command

Let me know what you think!

*Required field. Your comment will show up after approval from a moderator.

This tutorial has 14 comments