In SPSS, how do I merge two files?

The most common form of merging is what SPSS calls a parallel "matched merge", where two files are sequentially organized and combined to create one large file. To complete this process, each file must contain the same shared unique identification variable; this is used to sort on and then to merge on. This variable is the key by which the final merged file will be organized, and serves as an index of the process (e.g., record number or ID number).

To implement the merge:

  1. Use the SORT CASE command to sort each file you wish to merge on the index variable.
  2. After sorting, use the SAVE OUTPUT command to save each file to a systems file.
  3. Use the MATCH FILES command to merge the files and create a single, final version of the file.

The following example of this process merges two files, merge1.sav and merge2.sav, with the shared index variable v1, into a final file, sort.sav:

  GET FILE = merge1.sav.
  SORT CASE BY v1.
  SAVE OUTFILE = merge1.sav.

  GET FILE = merge2.sav.
  SORT CASE BY v1.
  SAVE OUTFILE = merge2.sav.

  MATCH FILES 
  /FILE=merge1.sav
  /FILE=merge2.sav
  /BY v1.

  SAVE OUTFILE = sort.sav.

For other types of file merging or more information, see the SPSS Command Syntax Reference (PDF).

If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200; staff are available for consultation Monday-Friday 9am-noon and by appointment.

This is document aeqf in the Knowledge Base.
Last modified on 2015-06-19 00:00:00.

Contact us

For help or to comment, email the UITS Support Center.