VECTOR: Short Form (VECTOR command)

VECTOR can be used to create a list of new variables and the vector that refers to them simultaneously. The short form of VECTOR specifies a prefix of alphanumeric characters followed, in parentheses, by the length of the vector (the number of variables to be created).

  • The new variable names must not conflict with existing variables. If the prefix starts with the # character, the new variables are created according to the rules for scratch variables.
  • More than one vector of the same length can be created by naming two or more prefixes before the length specification.
  • By default, variables created with VECTOR receive F8.2 formats. Alternative formats for the variables can be specified by including a format specification with the length specification within the parentheses. The format and length can be specified in either order and must be separated by at least one space or comma. If multiple vectors are created, the assigned format applies to all of them unless you specify otherwise.

Creating a Vector from a Set of New Scratch Variables

VECTOR #WORK(10).
  • The program creates the vector #WORK, which refers to 10 scratch variables: #WORK1, #WORK2, and so on, through #WORK10. Thus, the element #WORK(5) of the vector is the variable #WORK5.

Creating Multiple Vectors of the Same Length

VECTOR X,Y(5).
  • VECTOR creates the vectors X and Y, which refer to the new variables X1 through X5 and Y1 through Y5, respectively.

Specifying the Format of Vector Variables

VECTOR X(6,A5).
  • VECTOR assigns an A5 format to the variables X1 through X6.

Creating Multiple Vectors of Different Lengths and Formats

VECTOR X,Y(A5,6) Z(3,F2).
  • VECTOR assigns A5 formats to the variables X1 to X6 and Y1 to Y6, and F2 formats to the variables Z1 to Z3. It doesn’t matter whether the format or the length is specified first within the parentheses.

Predetermining Variable Order Using the Short Form of VECTOR

INPUT PROGRAM.
VECTOR X Y (4,F8.2).
DATA LIST / X4 Y4 X3 Y3 X2 Y2 X1 Y1 1-8.
END INPUT PROGRAM.
 
PRINT /X1 TO X4  Y1 TO Y4.
BEGIN DATA
49382716
49382716
49382716
END DATA.
  • The short form of VECTOR is used to establish the dictionary order of a group of variables before they are defined on a DATA LIST command. To predetermine variable order, both VECTOR and DATA LIST must be enclosed within the INPUT PROGRAM and END INPUT PROGRAM commands.
  • The order of the variables in the active dataset will be X1, X2, X3, and X4, and Y1, Y2, Y3, and Y4, even though they are defined in a different order on DATA LIST.
  • The program reads the variables with the F1 format specified on DATA LIST. It writes the variables with the output format assigned on VECTOR (F8.2).
  • Another method for predetermining variable order is to use NUMERIC (or STRING if the variables are string variables) before the DATA LIST command (see the example on variable order for the NUMERIC command) . The advantage of using NUMERIC or STRING is that you can assign mnemonic names to the variables.

Name Conflicts in Vector Assignments

INPUT PROGRAM.
NUMERIC MIN MINI_A MINI_B MINIM(F2).
COMPUTE MINI_A = MINI(2).  /*MINI is function MINIMUM.
VECTOR MINI(3,F2).
DO REPEAT I = 1 TO 3.
+  COMPUTE MINI(I) = -I.
END REPEAT.
COMPUTE MIN = MIN(1).     /*The second MIN is function MINIMUM.
COMPUTE MINI_B = MINI(2). /*MINI now references vector MINI
COMPUTE MINIM = MINIM(3). /*The second MINIM is function MINIMUM.
END CASE. 
END FILE.
END INPUT PROGRAM.
  • In this example, there are potential name conflicts between the scalars (the variables named on NUMERIC), the vectors (named on VECTOR), and the statistical function MINIMUM.
  • A name that is not followed by a left parenthesis is treated as a scalar.
  • When a name followed by a left parenthesis may refer to a vector element or a function, precedence is given to the vector.