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 />

LEAVE 797<br />

• Numeric variables named on LEAVE are initialized to 0 for the first case, and string variables<br />

are initialized to blanks. These variables are not reinitialized when new cases are<br />

read.<br />

COMPUTE TSALARY=TSALARY+SALARY.<br />

LEAVE TSALARY.<br />

FORMAT TSALARY (DOLLAR8)/ SALARY (DOLLAR7).<br />

• These commands keep a running total of salaries across all cases. SALARY is the variable<br />

containing the employee’s salary, and TSALARY is the new variable containing the<br />

cumulative salaries for all previous cases.<br />

• For the first case, TSALARY is initialized to 0, and TSALARY equals SALARY. For the rest<br />

of the cases, TSALARY stores the cumulative totals for SALARY.<br />

• LEAVE follows COMPUTE because TSALARY must first be defined before it can be specified<br />

on LEAVE.<br />

• If LEAVE were not specified for this computation, TSALARY would be initialized to systemmissing<br />

for all cases. TSALARY would remain system-missing because its value would be<br />

missing for every computation.<br />

Example<br />

SORT CASES DEPT.<br />

IF DEPT NE LAG(DEPT,1) TSALARY=0. /*Initialize for new dept<br />

COMPUTE TSALARY=TSALARY+SALARY. /*Sum salaries<br />

LEAVE TSALARY. /*Prevent initialization<br />

each case<br />

FORMAT TSALARY (DOLLAR8)/ SALARY (DOLLAR7).<br />

• These commands accumulate a sum across cases for each department.<br />

• SORT first sorts cases by the values of variable DEPT.<br />

• IF specifies that if the value of DEPT for the current case is not equal to the value of DEPT<br />

for the previous case, TSALARY equals 0. Thus, TSALARY is reset to 0 each time the value<br />

of DEPT changes. (For the first case in the file, the logical expression on IF is missing.<br />

However, the desired effect is obtained because LEAVE initializes TSALARY to 0 for the<br />

first case, independent of the IF statement.)<br />

• LEAVE prevents TSALARY from being initialized for cases within the same department.

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

Saved successfully!

Ooh no, something went wrong!