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.

Nested DO IF Structures<br />

DO IF 499<br />

To perform transformations involving logical tests on two variables, you can use nested<br />

DO IF—END IF structures.<br />

• There must be an END IF command for every DO IF command in the structure.<br />

Example<br />

DO IF (RACE EQ 5). /*Do whites<br />

+ DO IF (SEX EQ 2). /*White female<br />

+ COMPUTE SEXRACE=3.<br />

+ ELSE. /*White male<br />

+ COMPUTE SEXRACE=1.<br />

+ END IF. /*Whites done<br />

ELSE IF (SEX EQ 2).<br />

COMPUTE SEXRACE=4.<br />

/*Nonwhite female<br />

ELSE.<br />

COMPUTE SEXRACE=2.<br />

/*Nonwhite male<br />

END IF. /*Nonwhites done<br />

• This structure creates variable SEXRACE, which indicates both the sex and minority status<br />

of an individual.<br />

• An optional plus sign, minus sign, or period in the first column allows you to indent<br />

commands so you can easily see the nested structures.<br />

Complex File Structures<br />

Some complex file structures may require you to imbed more than one DATA LIST command<br />

inside a DO IF—END IF structure. For example, consider a data file that has been collected<br />

from various sources. The information from each source is basically the same, but it is in<br />

different places on the records:<br />

111295100FORD CHAPMAN AUTO SALES<br />

121199005VW MIDWEST VOLKSWAGEN SALES<br />

11 395025FORD BETTER USED CARS<br />

11 CHEVY 195005 HUFFMAN SALES & SERVICE<br />

11 VW 595020 MIDWEST VOLKSWAGEN SALES<br />

11<br />

12<br />

CHEVY 295015<br />

CHEVY 210 20<br />

SAM’S AUTO REPAIR<br />

LONGFELLOW CHEVROLET<br />

9555032 VW HYDE PARK IMPORTS<br />

In the above file, an automobile part number always appears in columns 1 and 2, and the automobile<br />

manufacturer always appears in columns 10 through 14. The location of other information,<br />

such as price and quantity, depends on both the part number and the type of automobile.<br />

The DO IF—END IF structure in the following example reads records for part type 11.

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

Saved successfully!

Ooh no, something went wrong!