27.03.2013 Views

SPSS® 12.0 Command Syntax Reference

SPSS® 12.0 Command Syntax Reference

SPSS® 12.0 Command Syntax Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

926 MATRIX—END MATRIX<br />

COMPUTE Statement<br />

The COMPUTE statement carries out most of the calculations in the matrix program. It closely<br />

resembles the COMPUTE command in the SPSS transformation language.<br />

• The basic specification is the target variable, an equals sign, and the assignment expression.<br />

Values of the target variable are calculated according to the specification on the assignment<br />

expression.<br />

• The target variable must be named first, and the equals sign is required. Only one target variable<br />

is allowed per COMPUTE statement.<br />

• Expressions that extract portions of a matrix, such as M(1,:) or M(1:3,4), are allowed to<br />

assign values. (See “Matrix Notation Shorthand” on p. 918.) The target variable must be<br />

specified as a variable.<br />

• Matrix functions must specify at least one argument enclosed in parentheses. If an expression<br />

has two or more arguments, each argument must be separated by a comma. For a<br />

complete discussion of the functions and their arguments, see “Matrix Functions” on p. 927.<br />

String Values on COMPUTE Statements<br />

Matrix variables, unlike those in the SPSS transformation language, are not checked for data<br />

type (numeric or string) when you use them in a COMPUTE statement.<br />

• Numerical calculations with matrices containing string values will produce meaningless<br />

results.<br />

• One or more elements of a matrix can be set equal to string constants by enclosing the string<br />

constants in apostrophes or quotation marks on a COMPUTE statement.<br />

• String values can be copied from one matrix to another with the COMPUTE statement.<br />

• There is no way to display a matrix that contains both numeric and string values, if you<br />

compute one for some reason.<br />

Example<br />

COMPUTE LABELS={"Observe", "Predict", "Error"}.<br />

PRINT LABELS /FORMAT=A7.<br />

• LABELS is a row vector containing three string values.<br />

Arithmetic Operations and Comparisons<br />

The expression on a COMPUTE statement can be formed from matrix constants and variables,<br />

combined with the arithmetic, relational, and logical operators discussed above. Matrix constructions<br />

and matrix functions are also allowed.<br />

Examples<br />

COMPUTE PI = 3.14159265.<br />

COMPUTE RSQ = R * R.<br />

COMPUTE FLAGS = EIGENVAL >= 1.<br />

COMPUTE ESTIM = {OBS, PRED, ERR}.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!