1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
* (Q) I have 7 excel files having the same variables. I need to combine these into a single sav files.
* (A) Posted to SPSSX-L list by Raynald Levesque on 2004/10/14.
* The example assumes there are only 3 excel files. Note that the ".xls" extension is not supplied 
 along with the file names. THe macro is valid for up to 50 files (this is a limitation of the 
 ADD FILES command).

*//////////////////////.
DEFINE !combine(pathd=!TOKENS(1) /fnames=!CMDEND)
!DO !file !IN (!fnames)
GET DATA /TYPE=XLS
   /FILE=!QUOTE(!CONCAT(!UNQUOTE(!pathd),!file,'.xls'))
   /SHEET=name 'employee1'
   /CELLRANGE=full
   /READNAMES=on .
SAVE OUTFILE=!QUOTE(!CONCAT(!UNQUOTE(!pathd),!file,'.sav')).
!DOEND

ADD FILES !DO !file !IN (!fnames) /FILE=!QUOTE(!CONCAT(!UNQUOTE(!pathd),!file,'.sav')) !DOEND.
!ENDDEFINE.
*//////////////////////.

SET MPRINT=yes.
!combine pathd='c:\\temp\\'
	fnames=employee1 employee2 employee3.
SET MPRINT=no.