```Date: Tue, 7 Oct 1997 17:20:52 -0500 Reply-To: "Matheson, David" Sender: "SPSSX(r) Discussion" From: "Matheson, David" Subject: Re: sequence of integers Comments: To: Melvin Klassen Actually, if N is a sequence of 1, 2, 3, 4, 5, 6 1 + MOD(N,3) returns 2, 3, 1, 2, 3, 1 and 4 - MOD(N,3) returns 3, 2, 4, 3, 2, 4 I'd suggest >compute A = 1 + mod(N-1,3). >compute B = 3 - mod(N-1,3). >execute. Whenever N is a multiple of 3, MOD(N,3) will return a 0. For the A series, the other numbers (that aren't mult of 3) are exactly what you want at that point. Adding 1 to this result gives you a repeating 1,2,3 series, but not starting at 1. For the B series, you get a 4, rather than a 1, in positions 3, 6, ...when subtracting from 4. With N defined as above N-1 = 0,1,2,3,4,5 and MOD(N-1,3) = 0,1,2,0,1,2 Adding 1 then gives you the desired A series and subtracting from 3 gives you the desired B series with the suggested starting points. If N is not defined, but you have an active data set, you can use >compute A = 1 + mod(\$casenum-1,3). >compute B = 3 - mod(\$casenum-1,3). >execute. David Matheson SPSS Technical Support >---------- >From: Melvin Klassen[SMTP:KLASSEN@UVVM.UVIC.CA] >Sent: Tuesday, October 07, 1997 3:00 PM >To: SPSSX-L@UGA.CC.UGA.EDU >Subject: Re: sequence of integers > >Anders Alexandersson & Maria Krol writes: >>On large SPSS datasets, how do you compute sequences of integers that >>restart? For instance, how do you compute variables A and B, where >>A=(1,2,3,1,2,3,1,2,3,...) and B=(3,2,1,3,2,1,3,2,1,...)? > >Given values of 1 or 2 or 3 or 4 or 5 or 6 or ... in the variable 'N', try: > > COMPUTE A = 1 + MOD(N,3) > COMPUTE B = 4 - MOD(N,3) > >That's all! > ```

Back to: Top of message | Previous page | Main SPSSX-L page