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.

DEFINE—!ENDDEFINE 457<br />

• The first loop concatenates var and the value for !I, which is 1 in the first loop. The second loop<br />

concatenates var and 2, and the third concatenates var and 3. The result is that FREQUENCIES<br />

is executed three times, with variables VAR1, VAR2, and VAR3, respectively.<br />

List-processing Loop<br />

The syntax of a list-processing loop is as follows:<br />

!DO !var !IN (list)<br />

statements<br />

!BREAK<br />

!DOEND<br />

• The !DO and !DOEND statements begin and end the loop. !BREAK is used to exit the loop.<br />

• The !IN function requires one argument, which must be a list of items. The number of<br />

items on the list determines the number of iterations. At each iteration, the index variable<br />

!var is set to each item on the list.<br />

• The list can be any expression, although it is usually a string. Only one list can be specified<br />

in each list-processing loop.<br />

Example<br />

DEFINE macdef (!POS !CHAREND(’/’) )<br />

!DO !i !IN ( !1)<br />

frequencies variables = !i.<br />

!DOEND<br />

!ENDDEFINE.<br />

macdef VAR1 VAR2 VAR3 /.<br />

• The macro call assigns three variables, VAR1, VAR2, and VAR3, to the positional argument<br />

!1. Thus, the loop completes three iterations.<br />

• In the first iteration, !i is set to value VAR1. In the second and third iterations, !I is set to<br />

VAR2 and VAR3, respectively. Thus, FREQUENCIES is executed three times, respectively<br />

with VAR1, VAR2, and VAR3.<br />

Example<br />

DEFINE macdef (!POS !CHAREND(’/’) )<br />

!DO !i !IN ( !1)<br />

sort cases by !i.<br />

report var = earnings<br />

/break = !i<br />

/summary = mean.<br />

!DOEND<br />

!ENDDEFINE.<br />

macdef SALESMAN REGION MONTH /.<br />

• The positional argument !1 is assigned the three variables SALESMAN, REGION, and<br />

MONTH. The loop is executed three times and the index variable !i is set to each of the variables<br />

in succession. The macro creates three reports.

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

Saved successfully!

Ooh no, something went wrong!