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.

Example<br />

DATA LIST 421<br />

INPUT PROGRAM.<br />

NUMERIC TINCOME (DOLLAR8.0). /* Total income<br />

LEAVE TINCOME.<br />

DO IF $CASENUM EQ 1.<br />

+ PRINT EJECT.<br />

+ PRINT / ’Name Income’.<br />

END IF<br />

DATA LIST FILE=INCOME END=#EOF NOTABLE / NAME 1-10(A)<br />

INCOME 16-20(F).<br />

DO IF #EOF.<br />

+ PRINT / ’TOTAL ’, TINCOME.<br />

+ END FILE.<br />

ELSE.<br />

+ PRINT / NAME, INCOME (A10,COMMA8).<br />

+ COMPUTE TINCOME = TINCOME+INCOME. /* Accumulate total income<br />

END IF.<br />

END INPUT PROGRAM.<br />

EXECUTE.<br />

• The data definition commands are enclosed within an INPUT PROGRAM—END INPUT<br />

PROGRAM structure.<br />

• NUMERIC indicates that a new numeric variable, TINCOME, will be created.<br />

• LEAVE tells the program to leave variable TINCOME at its value for the previous case as<br />

each new case is read, so that it can be used to accumulate totals across cases.<br />

• The first DO IF structure, enclosing the PRINT EJECT and PRINT commands, tells the<br />

program to display the headings Name and Income at the top of the display (when<br />

$CASENUM equals 1).<br />

• DATA LIST defines variables NAME and INCOME, and it specifies the scratch variable #EOF<br />

on the END subcommand.<br />

• The second DO IF prints the values for NAME and INCOME and accumulates the variable<br />

INCOME into TINCOME by passing control to ELSE as long as #EOF is not equal to 1. At<br />

the end of the file, #EOF equals 1, and the expression on DO IF is true. The label TOTAL<br />

and the value for TINCOME are displayed, and control is passed to END FILE.

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

Saved successfully!

Ooh no, something went wrong!