Examples (VECTOR command)
Example
DATA LIST FREE /height age weight.
BEGIN DATA
1 2 3
END DATA.
VECTOR x=height TO weight.
VECTOR y=age TO weight.
VECTOR z=age TO height.
- The list of variables specified with
TO
defines a list of variables in file order. - Vector x contains the variables height, age, and weight.
- Vector y contains the variables age and weight.
- The last
VECTOR
command generates an error because height comes before age in file order.
Example
* Replace a case's missing values with the mean of all
nonmissing values for that case.
DATA LIST FREE /V1 V2 V3 V4 V5 V6 V7 V8.
MISSING VALUES V1 TO V8 (99).
COMPUTE MEANSUB=MEAN(V1 TO V8).
VECTOR V=V1 TO V8.
LOOP #I=1 TO 8.
+ DO IF MISSING (V(#I)).
+ COMPUTE V(#I)=MEANSUB.
+ END IF.
END LOOP.
BEGIN DATA
1 99 2 3 5 6 7 8
2 3 4 5 6 7 8 9
2 3 5 5 6 7 8 99
END DATA.
LIST.
- The first
COMPUTE
command calculates the variable MEANSUB as the mean of all nonmissing values for each case. -
VECTOR
defines the vector V with the original variables as its elements. - For each case, the loop is executed once for each
variable. The
COMPUTE
command within the loop is executed only when the variable has a missing value for that case.COMPUTE
replaces the missing value with the value of MEANSUB. - For the first case, the missing value for the variable V2 is changed to the value of MEANSUB for that case. The missing value for the variable V8 for the third case is changed to the value of MEANSUB for that case.
For additional examples of VECTOR
, see the examples for the END CASE command and the IF command.