Understanding the SAS/IML Language


Command Statements

Command statements are used to perform specific system actions, such as storing and loading matrices and modules, or to perform special data processing requests. The following table lists some commands and the actions they perform.

Table 3.2: Command Statements

Statement

Description

FREE

Frees memory associated with a matrix

LOAD

Loads a matrix or module from a storage library

MATTRIB

Associates printing attributes with matrices

PRINT

Prints a matrix or message

RESET

Sets various system options

REMOVE

Removes a matrix or module from library storage

SHOW

Displays system information

STORE

Stores a matrix or module in the storage library


These commands play an important role in SAS/IML software. You can use them to control information displayed about matrices, symbols, or modules.

If a certain computation requires almost all of the memory on your computer, you can use commands to store extraneous matrices in the storage library, free the matrices of their values, and reload them later when you need them again. For example, the following statements define several matrices:

proc iml;
a = {1 2 3, 4 5 6, 7 8 9};
b = {2 2 2};
show names;

Figure 3.3: List of Symbols in RAM

 SYMBOL   ROWS   COLS TYPE   SIZE                                               
 ------ ------ ------ ---- ------                                               
 a           3      3 num       8                                               
 b           1      3 num       8                                               
  Number of symbols = 2  (includes those without values)                        
                                                                                



Suppose that you want to compute a quantity that does not involve the a matrix or the b matrix. You can store a and b in a library storage with the STORE command, and release the space with the FREE command. To list the matrices and modules in library storage, use the SHOW STORAGE command (or the STORAGE function), as shown in the following statements:

store a b;                 /* store the matrices */
show storage;              /* make sure the matrices are saved */
free a b;                  /* free the RAM */

The output from the SHOW STORAGE statement (see Figure 3.4) indicates that there are two matrices in storage. (There are no modules in storage for this example.)

Figure 3.4: List of Symbols in Storage

Contents of storage library = WORK.IMLSTOR                                      
                                                                                
Matrices:                                                                       
A                                B                                              
                                                                                
Modules:                                                                        
                                                                                



You can load these matrices from the storage library into RAM with the LOAD command, as shown in the following statement:

load a b;

See Chapter 18: Storage Features, for more details about storing modules and matrices.

Data Management Commands

SAS/IML software has many commands that enable you to manage your SAS data sets from within the SAS/IML environment. These data management commands operate on SAS data sets. There are also commands for accessing external files. The following table lists some commands and the actions they perform.

Table 3.3: Data Management Statements

Statement

Description

APPEND

Adds records to an output SAS data set

CLOSE

Closes a SAS data set

CREATE

Creates a new SAS data set

DELETE

Deletes records in an output SAS data set

EDIT

Reads from or writes to an existing SAS data set

FIND

Finds records that satisfy some condition

LIST

Lists records

PURGE

Purges records marked for deletion

READ

Reads records from a SAS data set into IML matrices

SETIN

Sets a SAS data set to be the input data set

SETOUT

Sets a SAS data set to be the output data set

SORT

Sorts a SAS data set

USE

Opens an existing SAS data set for reading


These commands can be used to perform data management. For example, you can read observations from a SAS data set into a target matrix with the USE or EDIT command. You can edit a SAS data set and append or delete records. If you have a matrix of values, you can output the values to a SAS data set with the APPEND command. See Chapter 7: Working with SAS Data Sets, and Chapter 8: File Access, for more information about these commands.