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.

784 KEYED DATA LIST<br />

Example<br />

* Reading a direct-access file: sampling 1 out of every 25 records.<br />

FILE HANDLE EMPL/ file specifications.<br />

INPUT PROGRAM.<br />

COMPUTE #INTRVL = TRUNC(UNIF(48))+1. /* Mean interval = 25<br />

COMPUTE #NXTCASE = #NXTCASE+#INTRVL. /* Next record number<br />

COMPUTE #EOF = #NXTCASE > 1000. /* End of file check<br />

DO IF #EOF.<br />

+ END FILE.<br />

ELSE.<br />

+ KEYED DATA LIST FILE=EMPL, KEY=#NXTCASE, IN=#FOUND, NOTABLE<br />

/YRHIRED 1-2 SEX 3 JOBCLASS 4.<br />

+ DO IF #FOUND.<br />

+ END CASE. /* Return a case<br />

+ ELSE.<br />

+ PRINT / ’Oops. #NXTCASE=’ #NXTCASE.<br />

+ END IF.<br />

END IF.<br />

END INPUT PROGRAM.<br />

EXECUTE.<br />

• FILE HANDLE defines the handle for the data file to be read by the KEYED DATA LIST<br />

command. The record numbers for this example are generated by the transformation<br />

language; they are not based on data taken from another file.<br />

• The INPUT PROGRAM and END INPUT PROGRAM commands begin and end the block of<br />

commands that build cases from the input file. Since the session generates cases, an input<br />

program is required.<br />

• The first two COMPUTE statements determine the number of the next record to be selected.<br />

This is done in two steps. First, the integer portion is taken from the sum of 1 and a uniform<br />

pseudo-random number between 1 and 49. The result is a mean interval of 25. Second, the<br />

variable #NXTCASE is added to this number to generate the next record number. This<br />

record number, #NXTCASE, will be used for the key variable on the KEYED DATA LIST<br />

command. The third COMPUTE creates a logical scratch variable, #EOF, that has a value<br />

of 0 if the record number is less than or equal to 1000, or 1 if the value of the record number<br />

is greater than 1000.<br />

• The DO IF—END IF structure controls the building of cases. If the record number is greater<br />

than 1000, #EOF equals 1, and the END FILE command tells the program to stop reading<br />

data and end the file.<br />

• If the record number is less than or equal to 1000, the record is read via KEYED DATA LIST<br />

using the value of #NXTCASE. A case is generated if the record exists (#FOUND equals 1).<br />

If not, the program displays the record number and continues to the next case. The sample<br />

will have about 40 records.<br />

• EXECUTE causes the transformations to be executed.<br />

• This example illustrates the difference between DATA LIST, which always reads the next<br />

record in a file, and KEYED DATA LIST, which reads only specified records. The record<br />

numbers must be generated by another command or be contained in the working data file.

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

Saved successfully!

Ooh no, something went wrong!