SPSS ADD FILES Command
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 Files Matches Data Sources on Variable Names
SPSS Add Files - Basic Usage
ADD FILES command illustrated in the screenshot above results from running the syntax below.
SPSS Add Files Syntax Example
data list free/v1 v2 v3.
1 1 1
dataset name d1.
*2. Create dataset d2.
data list free / v2 v1 v4.
2 2 2
dataset name d2.
*3. Merge d1 and d2.
add files file d1 / file d2.
dataset name merged.
SPSS Add Files Rules
- Up to 50 datasets or data files can be merged with a single
ADD FILEScan also be used for reordering and/or dropping variables in a single dataset. This is done by using the
DROPsubcommand. How it works is explained in
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
INsubcommand 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.