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
* To save a file having kn cases into k files of n cases each.
* Answer by rlevesque@videotron.ca.

*Generate a file of 200 cases for illustration purposes.
NEW file.
input program.
SET SEED=246813579.
loop caseid=1 to 200.
leave caseid. 
compute age=RND(uniform(100)).
COMPUTE gender=UNIFORM(1)>.5.
FORMATS caseid TO gender (F8.0).
end case.
end loop.
end file.
end input program.
execute.

SET MPRINT=ON.
*Define a macro which will do the job.
DEFINE !save_it (file=!TOKENS(1)
		/size=!TOKENS(1))
DO IF $casenum=1. 
	COMPUTE number1=1.
	COMPUTE file_nb=1.
ELSE IF lag(number1)<!size.
	COMPUTE  number1=lag(number1)+1.
	COMPUTE file_nb=lag(file_nb).
ELSE.
	COMPUTE number1=1.
	COMPUTE file_nb=lag(file_nb)+1.
END IF.

!DO !cnt=1 !TO !file.
	DO IF (file_nb=!cnt).
	XSAVE OUTFILE=!CONCAT("c:\\temp\\FILE",!cnt,".sav"). 
	END IF.
!DOEND.
!ENDDEFINE.

*to save the data in 4 files of 50 cases each.
!save_it file=4 size=50 .
EXECUTE.