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
42
43
* Initial file has STRING(A2) variable cat1 which has n different values.
* Objective is to create n different files.

* This creates a data file for illustration purposes.
* The syntax works for any number of different values of cat1.
	
* Posted by Raynald Levesque to SPSSX-L on 2001/08/09.
* Improved on 2003/01/24.

DATA LIST FREE /cat1(A2).
BEGIN DATA
"A2" "B7" "01" "08" "W7" "XY"
"A2" "A2" "08" "W7" "W7" "XY"
"A2" "B7" "01" "08" "W7" "XY"
END DATA.
LIST.

SAVE OUTFILE='c:\\temp\\mydata.sav'.

* Now start the job.
set mprint=on.

*//////////////////////////////////////////.
DEFINE !SPLIT (var=!TOKENS(1) /value=!TOKENS(1) )
TEMPORARY.
SELECT IF (!var=!value).
SAVE OUTFILE=!QUOTE(!CONCAT('c:\\temp\\f',!UNQUOTE(!value),'.sav')).
EXECUTE.
!ENDDEFINE.
*//////////////////////////////////////////.

* Find all different existing values of cat1.
AGGREGATE  /OUTFILE=*
  /BREAK=cat1  /notused = N.

* Write a syntax file which will call the above macro.
WRITE OUTFILE='c:\\temp\\temp.sps'
 /'!SPLIT var=cat1 value="' cat1 '".'.
Execute.

* Get the original data file and do the macro calls.
GET FILE='c:\\temp\\mydata.sav'.
INCLUDE 'C:\\temp\\temp.sps'.