SPSS ADD FILES Command

Summary

ADD FILES is an SPSS command that’s mainly used for merging data sources holding similar variables but different cases. (For the same cases but different variables, see MATCH FILES.) A second use is for reordering and/or dropping variables in a single dataset.

SPSS Add FilesSPSS Add Files Matches Data Sources on Variable Names

SPSS Add Files – Basic Usage

The ADD FILES command illustrated in the screenshot above results from running the syntax below.

SPSS Add Files Syntax Example

*1. Create dataset d1.

data list free/v1 v2 v3.
begin data
1 1 1
end data.dataset name d1.

*2. Create dataset d2.

data list free / v2 v1 v4.
begin data
2 2 2
end data.

dataset name d2.

*3. Merge d1 and d2.

add files file d1 / file d2.
exe.

dataset name merged.

SPSS Add Files Rules

  • Up to 50 datasets or data files can be merged with a single ADD FILES command.
  • ADD FILES can also be used for reordering and/or dropping variables in a single dataset. This is done by using the KEEP or DROP subcommand. How it works is explained in MATCH FILES.

SPSS Add Files Pitfalls

    • If a variable has inconsistent dictionary information across data sources, you may end up with nonsensical data. This is explained in SPSS Recode – Cautionary Note. For a tool that detects dictionary inconsistencies over files, see Compare Dictionaries over Files Before Merging.
    • If there are string variables present, they should have the same lengths across all data sources. Adjust String Lengths before Merging Files shows how to do this automatically using Python.
  • Especially with many data files, you may want to add the file names as a new variable to the files. Like so, you can easily see the source of each case in the merged data. See Add Filenames to Files Before Merging.
  • An alternative for adding the data sources to the merged result is using the IN subcommand as in add files file d1 /in = d1 / file d2 /in = d2.
  • If you want to merge a lot of files, you can have Python do it for you. This is demonstrated in Merge Many Data Files.

Post Author: Zahid Farid