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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
* (Q) I need a macro which will accept 5 values
	the seed
	the number of integers needed
	the low value
	the high value
	the increment (default to 1)
	and will generate the id of the cases to be selected (cases are not computerized).
	
*	The list should then be printed 10 by lines (with a space between the 5th and 6th number) in 
	a) selection order and b) in id order.

* (A) Answer posted to SPSSX-L by rlevesque@videotron.ca on 2001/08/14.
* http://www.spsstools.net

* This macro will be called by the main macro. You should select one of the print method and delete the 
	other from this macro. The printout of the second method is in the LOG, so this must be enabled.
* Two examples of how to use the macro are given at the end.

*//////////////////////////////.
DEFINE !print()
vector id(10F6.0).
compute idx=mod(selorder,10).
if idx=0 idx=10.
compute id(idx)=id.
compute linenb=trunc(selorder/10.1)+1.

AGGREGATE
  /OUTFILE=*
  /BREAK=linenb
  /id1 TO id10 = FIRST(id1 TO id10).

* choose one of the following print method.
* using summarize.
string space(A1).
variable label space ' '.
SUMMARIZE
  /TABLES=id1 to id5 space id6 to id10
  /FORMAT=VALIDLIST NOCASENUM TOTAL
  /TITLE='Case Summaries'
  /MISSING=VARIABLE
  /CELLS=NONE.

* using print.
print /id1 id2 id3 id4 id5 '    ' id6 id7 id8 id9 id10.
execute.
!ENDDEFINE.
*//////////////////////////////.


*/////////////////////////////.
DEFINE !getlist (seed=!TOKENS(1) 
	/nbreq=!TOKENS(1)
	/min=!TOKENS(1)
	/max=!TOKENS(1)
	/incr=!TOKENS(1) !DEFAULT(1))
set seed=!seed.  
input program.
loop #1 = !min to !max by !incr. 
compute ranorder= rv.normal(0,1).
compute id= #1.
end case.
end loop.
end file.
end input program.
formats ranorder (f8.6).
sort cases by ranorder.
compute selorder= $casenum.
formats id selorder (f6).
select if $casenum LE !nbreq.
print /selorder id.
save outfile='c:\\temp\\all cases.sav'.

* print results by selection order.
!print.

get file='c:\\temp\\all cases.sav'.
sort cases by id.
* print results by id order.
!print.

!ENDDEFINE.
*/////////////////////////////.


* Example 1.
!getlist seed=66754798 nbreq=50 min=100 max=200 incr=2.

* Example 2 (using default value of incr).
!getlist seed=12345678 nbreq=60 min=100 max=200 .