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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Examples<br />

COMPUTE 255<br />

• The string returned by a string expression does not have to be the same width as the target<br />

variable. If the target variable is shorter, the result is right-trimmed. If the target variable<br />

is longer, the result is right-padded. The program displays no warning messages when<br />

trimming or padding.<br />

• To control the width of strings, use the functions that are available for padding (LPAD,<br />

RPAD), trimming (LTRIM, RTRIM), and selecting a portion of strings (SUBSTR).<br />

• To determine whether a character in a string is single-byte or double-byte, use the<br />

MBLEN.BYTE function. Specify the string and, optionally, its beginning byte position. If<br />

the position is not specified, it defaults to 1.<br />

The following examples illustrate the use of COMPUTE. For a complete discussion of each<br />

function, see “Transformation Expressions” on p. 37.<br />

Arithmetic Operations<br />

COMPUTE V1=25-V2.<br />

COMPUTE V3=(V2/V4)*100.<br />

DO IF TENURE GT 5.<br />

COMPUTE RAISE=SALARY*.12.<br />

ELSE IF TENURE GT 1.<br />

COMPUTE RAISE=SALARY*.1.<br />

ELSE.<br />

COMPUTE RAISE=0.<br />

END IF.<br />

• V1 is 25 minus V2 for all cases. V3 is V2 expressed as a percentage of V4.<br />

• RAISE is 12% of SALARY if TENURE is greater than 5. For remaining cases, RAISE is 10%<br />

of SALARY if TENURE is greater than 1. For all other cases, RAISE is 0.<br />

Arithmetic Functions<br />

COMPUTE WTCHANGE=ABS(WEIGHT1-WEIGHT2).<br />

COMPUTE NEWVAR=RND((V1/V2)*100).<br />

COMPUTE INCOME=TRUNC(INCOME).<br />

COMPUTE MINSQRT=SQRT(MIN(V1,V2,V3,V4)).<br />

COMPUTE TEST = TRUNC(SQRT(X/Y)) * .5.<br />

COMPUTE PARENS = TRUNC(SQRT(X/Y) * .5).<br />

• WTCHANGE is the absolute value of WEIGHT1 minus WEIGHT2.<br />

• NEWVAR is the percentage V1 is of V2, rounded to an integer.<br />

• INCOME is truncated to an integer.<br />

• MINSQRT is the square root of the minimum value of the four variables V1 to V4. MIN<br />

determines the minimum value of the four variables, and SQRT computes the square root.

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

Saved successfully!

Ooh no, something went wrong!