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
*(Q) I am going to simulate random variables that comes in triads: 
 var1a, var1b, var1c, var2a, var2b, var2c etc.
*Each variable can take the random integer values 0,1 and 2 bUT 
 each of the three variables in a triad (e.g. var2a, var2b, var2c)
 must have DIFFERENT values.
*So the first of the three variables can take any of the values 0, 1, 2 (I used
 COMPUTE var1a  = TRUNC(RV.UNIFORM(0,3)) .)
*The second variable can take any of the three EXCEPT the one taken by the first variable.
*The third variable is 3 minus the sum of the first two

*My problem is how to get the second variable.
*(and perhaps an elegant solution for the whole thing with a loop or something).

* (A) Posted to SPSSX-L by rlevesque@videotron.ca on 2002/01/08.

* Say you need to generate 4 triad random values for 10 cases.

INPUT PROGRAM.
LOOP id=1 TO 10.
LOOP varn=1 TO 4.
LEAVE id,varn.
LOOP ctr=1 TO 3.
END CASE.
END LOOP.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
LIST.

COMPUTE draw=UNIFORM(1).
* Rank the values within id and var.
RANK VARIABLES=draw BY id varn /RANK INTO rk.

* 4 variables of 3 values each gives 12 variables.
VECTOR var(12).
COMPUTE var((varn-1)*3+ctr)=rk.

* Collapse cases to one line per id.
AGGREGATE
  /OUTFILE=*
  /BREAK=id
  /var1 TO var12 = MAX(var1 TO var12).

RENAME VARIABLES (var1 TO var3 = var1a var1b var1c)
	/(var4 TO var6 = var2a var2b var2c)
	/(var7 TO var9 = var3a var3b var3c)
	/(var10 TO var12 = var4a var4b var4c).