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.

1434 REREAD<br />

FILE Subcommand<br />

FILE specifies an external raw data file from which the next DATA LIST command reads data.<br />

• The default file is the file specified on the immediately preceding DATA LIST command.<br />

• If the file specified on FILE is not the default file, the same file must be specified on the<br />

next DATA LIST. Otherwise, the FILE subcommand is ignored and the DATA LIST command<br />

reads the next record from the file specified on it or, if no file is specified, from the file<br />

specified on the previous DATA LIST command.<br />

Example<br />

INPUT PROGRAM.<br />

DATA LIST FILE=UPDATE END=#EOF NOTABLE<br />

/#ID 1-3. /*Get rep ID in new sales file.<br />

DATA LIST FILE = SALESREP NOTABLE<br />

/ID 1-3 SALES 4-11(F,2)<br />

NEWSALE 12-19(F,2). /*Get rep record from master file.<br />

LOOP IF #EOF OR (#ID GT ID). /*If UPDATE ends or no new sales made.<br />

+ COMPUTE NEWSALE = 0. /*Set NEWSALE to 0<br />

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

+ DATA LIST FILE = SALESREP NOTABLE<br />

/ID 1-3 SALES 4-11(F,2)<br />

NEWSALE 12-19(F,2). /*Continue reading masterfile.<br />

END LOOP<br />

DO IF NOT #EOF. /*If new sales made.<br />

+ REREAD FILE=UPDATE COLUMN = 4. /*Read new sales from UPDATE.<br />

+ DATA LIST FILE=UPDATE<br />

/NEWSALE 1-8(F,2).<br />

+ COMPUTE SALES=SALES+NEWSALE. /*Update master file.<br />

END IF.<br />

END CASE. /*Build a case.<br />

END INPUT PROGRAM.<br />

LIST.<br />

• This example uses REREAD to merge two raw data files (SALESREP and UPDATE).<br />

• Both files are sorted by sales representative ID number. The UPDATE file contains<br />

only records for sales representatives who have made new sales, with variables ID and<br />

NEWSALE. The master file SALESREP contains records for all sales representatives,<br />

with variables SALES (which contains year-to-date sales) and NEWSALE (which<br />

contains the update values each time the file is updated).<br />

• If a sales representative has made no new sales, there is no matching ID in the UPDATE<br />

file. When UPDATE is exhausted or when the ID’s in the two files do not match, the loop<br />

structure causes the program to build a case with NEWSALE equal to 0 and then continue<br />

reading the master file.<br />

• When the ID’s match (and the UPDATE file is not yet exhausted), the REREAD command<br />

is executed. The following DATA LIST rereads the record in UPDATE that matches the ID<br />

variable. NEWSALE is read from the UPDATE file starting from column 4 and SALES is<br />

updated. Note that the following DATA LIST specifies the same file.

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

Saved successfully!

Ooh no, something went wrong!