Overview (VECTOR command)

VECTOR associates a vector name with a set of existing variables or defines a vector of new variables. A vector is a set of variables that can be referred to using an index. The vector can refer to either string or numeric variables, and the variables can be permanent or temporary.

For each variable in the reference list, VECTOR generates an element. Element names are formed by adding a subscript in parentheses to the end of the vector name. For example, if the vector AGES has three elements, the element names are AGES(1), AGES(2), and AGES(3). Although the VECTOR command has other uses within the transformation language, it is most often used with LOOP structures because the indexing variable on LOOP can be used to refer to successive vector elements.

Options

File Structures. VECTOR can be used with the END CASE command to restructure data files. You can build a single case from several cases or, conversely, you can build several cases from a single case (see the examples for the END CASE command) .

Short-Form Vectors. VECTOR can be used to create a list of new variables and the vector that refers to them simultaneously. VECTOR in the short form can be used to establish the dictionary order of a group of variables before they are defined on a DATA LIST command (see VECTOR: Short Form) .

Basic Specification

  • The basic specification is VECTOR, a vector name, a required equals sign, and the list of variables that the vector refers to. The TO keyword must be used to specify the variable list, and it defines a variable list based on file order.
  • For the short form of VECTOR, the basic specification is VECTOR, an alphabetical prefix, and, in parentheses, the number of variables to be created.

Syntax Rules

  • Multiple vectors can be created on the same command by using a slash to separate each set of specifications.
  • Variables specified on VECTOR must already be defined unless the short form of VECTOR is used to create variables (see VECTOR: Short Form) .
  • 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.
  • A single vector must comprise all numeric variables or all string variables. The string variables must have the same length.
  • A scalar (a variable named on NUMERIC), a function, and a vector can all have the same name, for example MINI. The scalar can be identified by the lack of a left parenthesis following the name. Where a vector has the same name as a function (or the abbreviation of a function), the vector name takes precedence (see the example on name conflicts in VECTOR: Short Form) .
  • Vector element names must always be specified with a subscript in parentheses.

Operations

  • VECTOR takes effect as soon as it is encountered in the command sequence, unlike most transformations, which do not take effect until the data are read. Thus, special attention should be paid to its position among commands. See the topic Command Order for more information.
  • VECTOR is in effect only until the first procedure that follows it. The vector must be redeclared to be reused.

Limitations

  • A vector element is an expression and can be used wherever an expression can be used in transformation commands. It can also be the target of an assignment in a COMPUTE or IF command. It cannot be used in other transformation commands where a variable name is required. Specifically, vector elements cannot be used instead of variable names in RECODE, COUNT, XSAVE, DO REPEAT, or other transformation commands that require variable names but not expressions.
  • Vectors cannot be used in procedure commands (for example, statistical or charting procedures).
  • Vector names (for the whole vector rather than elements) cannot be used anywhere but in the VECTOR command itself.