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.

456 DEFINE—!ENDDEFINE<br />

• In the first macro, !IF(!type = A) is evaluated as false if the value of the unquoted string<br />

constant is lower case ‘a’ -- and is therefore evaluated as false in this example.<br />

• Prior to SPSS <strong>12.0</strong>, !IF (!type = A) was evaluated as true if the value of the unquoted string<br />

constant was lower case ‘a’ or upper case ‘A’ -- and was therefore evaluated as true in<br />

this example.<br />

• In the second macro, !IF (!type = ‘A’) is always evaluated as false if the value of the string<br />

constant is lower case ‘a’.<br />

Looping Constructs<br />

Looping constructs accomplish repetitive tasks. Loops can be nested to whatever depth is<br />

required, but loops cannot be crossed. The macro facility has two looping constructs: the<br />

index loop (DO loop) and the list-processing loop (DO IN loop).<br />

• When a macro is expanded, looping constructs are interpreted after arguments are substituted<br />

and functions are executed.<br />

Index Loop<br />

The syntax of an index loop is as follows:<br />

!DO !var = start !TO finish [ !BY step ]<br />

statements<br />

!BREAK<br />

!DOEND<br />

• The indexing variable is !var and must begin with an exclamation point.<br />

• The start, finish, and step values must be numbers or expressions that evaluate to numbers.<br />

• The loop begins at the start value and continues until it reaches the finish value (unless a<br />

!BREAK statement is encountered). The step value is optional and can be used to specify<br />

a subset of iterations. If start is set to 1, finish to 10, and step to 3, the loop will be<br />

executed four times with the index variable assigned values 1, 4, 7, and 10.<br />

• The statements can be any valid commands or macro keywords. !DOEND specifies the end<br />

of the loop.<br />

• !BREAK is an optional specification. It can be used in conjunction with conditional<br />

processing to exit the loop.<br />

Example<br />

DEFINE macdef (arg1 = !TOKENS(1)<br />

/arg2 = !TOKENS(1))<br />

!DO !i = !arg1 !TO !arg2.<br />

frequencies variables = !CONCAT(var,!i).<br />

!DOEND<br />

!ENDDEFINE.<br />

macdef arg1 = 1 arg2 = 3.<br />

• The variable !i is initially assigned the value 1 (arg1) and is incremented until it equals 3<br />

(arg2), at which point the loop ends.

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

Saved successfully!

Ooh no, something went wrong!