Use the READ Statement with the INTO Clause

Sometimes it is convenient to read all the numeric variables into columns of a matrix. To do this, use the READ statement with the INTO clause and specify the name of a matrix to create. Each variable that is specified in the VAR clause becomes a column of the target matrix. If there are $p$ variables in the VAR clause and $n$ observations are processed, the target matrix is an $n \times p$ matrix.

The following statement creates a matrix X that contains the first five observations of the numeric variables of the Sashelp.Class data set. The keyword _NUM_ in the VAR clause specifies that all numeric variables be read.

proc iml;
use Sashelp.Class;
read point (1:5) var _NUM_ into X;
print X;

Figure 7.12: All Numeric Variables

X
14 69 112.5
13 56.5 84
13 65.3 98
14 62.8 102.5
14 63.5 102.5


Every SAS/IML matrix is of either character or numeric type. Therefore, when you read data by using the INTO clause, you should use the _NUM_ or _CHAR_ keyword to specify the types of variables that you want to read. If you use the _ALL_ keyword with the INTO statement, all numeric variables are read.