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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
* Apply a macro to every file whose name is in a sav file.SPS.

* Apply a given macro to every file whose name is in a sav file.

DATA LIST FIXED /id 1-2 (F) fname 3-22 (A).
BEGIN DATA
1 employee data.sav
2 Fat surfactant.sav 
3 flying.sav
4 Glass strain.sav
END DATA.
LIST.
SAVE OUTFILE='c:\\temp\\list file names.sav'.

* This is the given macro.
*//////////.
DEFINE !count(file=!CMDEND)
COMPUTE xyz=1.
SUMMARIZE
  /TABLES=xyz
  /FORMAT=NOCASENUM TOTAL
  /TITLE=!QUOTE(!CONCAT('Number of cases in file ',!file)) 
  /MISSING=VARIABLE
  /CELLS=COUNT .
!ENDDEFINE.
*//////////.

/* Write a syntax file which loads each file named in */
/* "list file names.sav" and calls the macro !count	*/

GET FILE='c:\\temp\\list file names.sav'.
STRING fn(A50).
COMPUTE fn=CONCAT("c:\\Program Files\\SPSS\\",fname).
WRITE OUTFILE='c:\\temp\\do all files.sps' 
	/'GET FILE="' fn '".'
	/'!count file='fname'.'.
EXECUTE.
SET MPRINT=yes.

* Run the syntax file we just created.
INCLUDE 'c:\\temp\\do all files.sps'.