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.

Example<br />

* Reading a keyed file: reading selected records.<br />

KEYED DATA LIST 785<br />

GET FILE=STUDENTS/KEEP=AGE,SEX,COURSE.<br />

FILE HANDLE COURSES/ file specifications.<br />

STRING #KEY(A4).<br />

COMPUTE #KEY = STRING(COURSE,N4). /* Create a string key<br />

KEYED DATA LIST FILE=COURSES KEY=#KEY IN=#FOUND NOTABLE<br />

/PERIOD 13 CREDITS 16.<br />

SELECT IF #FOUND.<br />

LIST.<br />

• GET reads the STUDENTS file, which contains information on students, including a course<br />

identification for each student. The course identification will be used as the key for<br />

selecting one record from a file of courses.<br />

• The FILE HANDLE command defines a file handle for the file of courses.<br />

• The STRING and COMPUTE commands transform the course identification from numeric<br />

to string for use as a key. For keyed files, the key variable must be a string.<br />

• KEYED DATA LIST uses the value of the newly created string variable #KEY as the key to<br />

search the course file. If a record that matches the value of #KEY is found, #FOUND is set<br />

to 1; otherwise, it is set to 0. Note that KEYED DATA LIST appears outside an input program<br />

in this example.<br />

• If the course file contains the requested record, #FOUND equals 1. The variables PERIOD<br />

and CREDITS are added to the case and the case is selected via the SELECT IF command;<br />

otherwise, the case is dropped.<br />

• LIST lists the values of the selected cases.<br />

• This example shows how existing cases can be updated on the basis of information read<br />

from a keyed file.<br />

• This task could also be accomplished by reading the entire course file with DATA LIST<br />

and combining it with the student file via the MATCH FILES command. The technique<br />

you should use depends on the percentage of the records in the course file that need to<br />

be accessed. If fewer than 10% of the course file records are read, KEYED DATA LIST is<br />

probably more efficient. As the percentage of the records that are read increases,<br />

reading the entire course file and using MATCH makes more sense.<br />

FILE Subcommand<br />

FILE specifies the handle for the direct-access or keyed data file. The file handle must have<br />

been defined on a previous FILE HANDLE command (or, in the case of the IBM OS environment,<br />

on a DD statement in the JCL).<br />

KEY Subcommand<br />

KEY specifies the variable whose value will be used as the key. This variable must already<br />

exist as the result of a prior DATA LIST, KEYED DATA LIST, GET, or transformation command.

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

Saved successfully!

Ooh no, something went wrong!