# How to use VECTOR to work with every Nth variable

## Technote (FAQ)

## Question

In the Syntax Reference Guide, under the chapter, VECTOR, in the Syntax Rules section, it states,

'The TO convention must be used to specify the variable list. Thus, variables specified must be consecutive and must be from the same dictionary, permanent or scratch.'

Within my variable set, I would only like to work with every Nth variable, using VECTOR. I do not want to rearrange my variables so that every Nth variable becomes consecutive. What can I do?

## Answer

Use the VECTOR in terms of (#I*n), whereby n is a positive integer. For example, imagine you had a VECTOR, varset, that referred to existing consecutive variables, time1 to time12. If you wanted to only work with every third variable, use the VECTOR in terms of varset(#I*3). Only every third variable beginning with the third variable will then be included.

Below is an example.

*Data List is used to create sample data. The variables, id, and time1 to time12 are created.

DATA LIST/ id 1 time1 3 time2 5 time3 7 time4 9 time5 11 time6 13 time7 15 time8 17 time9 19 time10 21 time11 23 time12 25.

BEGIN DATA

1 2 3 4 5 6 7 8 9 0 0 1 3

2 1 2 1 2 1 2 1 2 1 2 2 3

3 1 3 4 5 6 1 2 0 1 0 2 4

4 0 2 3 5 1 2 1 2 9 6 6 4

5 1 4 6 4 3 2 1 8 2 0 2 7

6 4 5 1 4 6 8 9 0 1 0 5 7

7 0 4 5 9 3 4 5 8 4 0 2 3

8 0 6 7 4 6 3 7 3 5 7 3 2

9 1 1 1 5 7 5 5 5 6 1 2 2

END DATA.

EXE.

*Commands.

VECTOR varset= time1 to time12/ mult(4).

LOOP #I= 1 to 4.

COMPUTE mult(#I)= varset(#I*3).

END LOOP.

EXE.

*In the above commands, the VECTOR, varset, refers to the exising group of variables, time1 to time12. The vector, mult, is used to create four new variables, mult1 to mult4. The mult variables are populated with every third variable as indicated by the line, COMPUTE mult(#I)= varset(#I*3). Specify a different positive integer for a different multiple of variables. For example, if you wanted to include only every fourth variable out of the VECTOR, change the 3 in varset(#I*3) to varset(#I*4)

## Historical Number

40410

### Document information

**More support for:**
SPSS Statistics

**Software version:**
Not Applicable

**Operating system(s):**
Platform Independent

**Reference #:**
1475255

**Modified date:**
09 May 2013