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.

Equivalence<br />

COMPUTE 259<br />

STRING DEPT(A20).<br />

COMPUTE DEPT=’Personnel Department’.<br />

COMPUTE OLDVAR=NEWVAL.<br />

• DEPT is a new string variable and must be specified on STRING before it can be specified<br />

on COMPUTE. STRING assigns DEPT a width of 20 characters, and COMPUTE assigns the<br />

value Personnel Department to DEPT for each case.<br />

• OLDVAR must already exist; otherwise, it would have to be declared on STRING. The<br />

values of OLDVAR are modified to equal the values of NEWVAL. NEWVAL must be an<br />

existing string variable. If the dictionary width of NEWVAL is longer than the dictionary<br />

width of OLDVAR, the modified values of OLDVAR are truncated.<br />

String Functions<br />

STRING NEWSTR(A7) / DATE(A8) / #MO #DA #YR (A2).<br />

COMPUTE NEWSTR=LAG(OLDSTR,2).<br />

COMPUTE #MO=STRING(MONTH,F2.0).<br />

COMPUTE #DA=STRING(DAY,F2.0).<br />

COMPUTE #YR=STRING(YEAR,F2.0).<br />

COMPUTE DATE=CONCAT(#MO,’/’,#DA,’/’,#YR).<br />

COMPUTE LNAME=UPCASE(LNAME).<br />

• STRING declares NEWSTR as a new string variable with a width of seven characters, DATE<br />

with a width of eight characters, and scratch variables #MO, #DA, and #YR with a width of<br />

two characters each.<br />

• The first COMPUTE sets NEWSTR equal to the value of OLDSTR for two cases previous.<br />

The first two cases receive the system-missing value for NEWSTR.<br />

• The next three COMPUTE commands convert the existing numeric variables MONTH,<br />

DAY, and YEAR to the temporary string variables #MO, #DA, and #YR so that they can be<br />

used with the CONCAT function. The next COMPUTE assigns the concatenated value of<br />

#MO, #DA, and #YR, separated by slashes, to DATE. If #MO is 10, #DA is 16, and #YR is<br />

49, DATE is 10/16/49.<br />

• The final COMPUTE converts lowercase letters for the existing string variable LNAME to<br />

uppercase letters.

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

Saved successfully!

Ooh no, something went wrong!