*(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).