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.

740 IF<br />

Example<br />

Example<br />

* Test for listwise deletion of missing values.<br />

DATA LIST /V1 TO V6 1-6.<br />

STRING SELECT(A1).<br />

COMPUTE SELECT=’V’.<br />

VECTOR V=V1 TO V6.<br />

LOOP #I=1 TO 6.<br />

IF MISSING(V(#I)) SELECT=’M’.<br />

END LOOP.<br />

BEGIN DATA<br />

123456<br />

56<br />

1 3456<br />

123456<br />

123456<br />

END DATA.<br />

FREQUENCIES VAR=SELECT.<br />

• STRING creates the string variable SELECT with an A1 format and COMPUTE sets the<br />

value of SELECT to V.<br />

• VECTOR defines the vector V as the original variables V1 to V6. Variables on a single<br />

vector must be all numeric or all string variables. In this example, because the vector V is<br />

used as an argument on the MISSING function of IF, the variables must be numeric<br />

(MISSING is not available for string variables).<br />

• The loop structure executes six times: once for each VECTOR element. If a value is<br />

missing for any element, SELECT is set equal to M. In effect, if any case has a missing<br />

value for any of the variables V1 to V6, SELECT is set to M.<br />

• FREQUENCIES generates a frequency table for SELECT. The table gives a count of how<br />

many cases have missing values for at least one variable and how many cases have valid<br />

values for all variables. This table can be used to determine how many cases would be<br />

dropped from an analysis that uses listwise deletion of missing values. See pp. 257 and<br />

497 for alternative ways to test for listwise deletion of missing values.<br />

IF YRHIRED LT 1980 RATE=0.02.<br />

IF DEPT=’SALES’ DIVISION=’TRANSFERRED’.<br />

• The logical expression on the first IF command tests whether YRHIRED is less than 1980<br />

(hired before 1980). If so, the variable RATE is set to 0.02.<br />

• The logical expression on the second IF command tests whether DEPT equals SALES.<br />

When the condition is true, the value for the string variable DIVISION is changed to<br />

TRANSFERRED but is truncated if the format for DIVISION is not at least 11 characters<br />

wide. For any other value of DEPT, the value of DIVISION remains unchanged.<br />

• Although there are two IF statements, each defines a separate and independent condition.<br />

The IF command is used rather than the DO IF—END IF structure in order to test both condi-

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

Saved successfully!

Ooh no, something went wrong!