SAS/IML Programming Statements

Control statements the SAS/IML programming language enable you to control the path of execution in a program. These statements are similar to the corresponding statements in the SAS DATA step. There are essentially six different types of control statements in the SAS/IML programming language:

Selection Statements

Selection statemements choose one of several control paths in a program. The SAS/IML language supports the IF-THEN and the IF-THEN/ELSE statements. You can use an IF-THEN statement to test an expression and to conditionally perform an operation. You can also optionally specify an ELSE statement. The general form of the IF-THEN/ELSE statement is as follows:

	IF expression THEN statement1 ;
	ELSE statement2 ;

The expression is evaluated first. If the value of expression is true (which means nonzero and nonmissing), the THEN statement is executed. If the value of expression is false (which means zero or missing), the ELSE statement (if present) is executed. If an ELSE statement is not present, control passes to the next statement in the program.

Compound Statements

Several statements can be grouped together into a compound statement (also called a block or a DO group). You use a DO statement to define the beginning of a DO group and an END statement to define the end. DO groups have two principal uses:

DO groups have the following general form:


Iteration Statements

The SAS/IML language provides the following four variations of a DO statement that iterate over compound statements:

Jump Statements

Normally, SAS/IML software executes each statement in a program in sequence. However, the GOTO and LINK statements cause a SAS/IML program to jump from one statement in a program to another statement without executing intervening statements. The destination statement is identified by a label, which is a name followed by a colon placed before an executable statement. You can program a jump by using either the GOTO statement or the LINK statement:

	GOTO label;

	LINK label;

Statements That Define and Execute Modules

Modules are used to create a user-defined subroutine or function. A module definition begins with a START statement, which has the following general form:

	START <name> <( arguments )> <GLOBAL( arguments )>;

A module definition ends with a FINISH statement, which has the following general form:

	FINISH <name>;

To execute a module, you can use either a RUN statement or a CALL statement. The general forms of these statements are as follows:

	RUN <name> <( arguments)>;
	CALL <name> <( arguments)>;

The only difference between the RUN and CALL statements is the order of resolution.

Termination Statements

You can stop execution with a PAUSE, STOP, or ABORT statement. The QUIT statement is also a termination statement, but it causes the IML procedure to immediately exit. The other termination statements do not cause PROC IML to exit until the statements are executed.