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
* QUESTION: I want to split a file in two random pieces. I want to do this n times and keep track of all the n splits in the same data file.
* ASNWER by Ray.
* www.spsstools.net
*.

SET MPRINT=no.
* Create dummy data for illustration purposes.
NEW file.
input program.
loop id_org=1 to 10.
leave id_org.
COMPUTE #nb_ees=4+TRUNC(UNIFORM(10)).
loop id_ee=1 to #nb_ees.
+	compute dept=1+TRUNC(uniform(5)).
+	end case.
end loop.
end loop.
end file.
end input program.
execute.
SAVE OUTFILE='c:\\temp\\temp.sav'.

* Define macro.

*///////////////////////////////.
DEFINE !do_job (n_samp=!TOKENS(1))
!DO !cnt=1 !TO !n_samp.
GET FILE='c:\\temp\\temp.sav'.
COMPUTE randval = UNIFORM(1).
SORT CASES BY id_org randval.
COMPUTE seqnum = $casenum.
COMPUTE choose1 = MOD(seqnum,2).
/*do your analysis here*/.
SAVE OUTFILE=!QUOTE(!CONCAT('c:\\temp\\data',!cnt,'.sav')).
!DOEND
!ENDDEFINE.
*///////////////////////////////.

SET MPRINT=yes.
* Call macro.
!do_job n_samp=3.

* set n_samp equal to the desired number of samples.