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 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.
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 theKEEP
orDROP
subcommand. How it works is explained inMATCH 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 inadd 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 !!0250.
THIS TUTORIAL HAS 4 COMMENTS:
By Bjørn Bruland on September 9th, 2018
I believe I have used the solution described in the two url’s below and found them very helpful. Both procedures using Python. Now I get the message “Error 404 - Page Not Found”. Is it possible to “activate” the pages I am referring to?
http://www.spss-tutorials.com/add-filenames-to-files-before-merging/
http://www.spss-tutorials.com/merge-many-data-files/
By Ruben Geert van den Berg on September 9th, 2018
Hi Bjørn!
I considered both tutorials outdated and low quality so I removed them. I should have removed those links as well. I still have the syntax in my archives. It works but it's not well written. I'll send you the files by email.
Hope that helps!
By Soyeon Choi on August 5th, 2020
Hi,
I have the same question as Bjørn. Is it possible to access the archived syntax you mentioned above for these links?:
https://www.spss-tutorials.com/adjust-string-lengths-before-merging-files/
https://www.spss-tutorials.com/add-filenames-to-files-before-merging/
https://www.spss-tutorials.com/merge-many-data-files/
Thank you!
By Raina on June 26th, 2021
Hello! The link to the "Merge Many Data Files" referenced above is broken. I wouldlove to see this topic!