Use the READ statement
with the VAR clause to read variables from the current SAS data set into column vectors. Each variable in the VAR clause becomes
a column vector with the same name as the variable in the SAS data set. The number of rows is equal to the number of observations
that are processed, depending on the range specification and the WHERE clause. For example, to read the numeric variables Age
, Height
, and Weight
for all observations in the Sashelp.Class
data set, use the following statements:
proc iml; use Sashelp.Class; read all var {Age Height Weight}; close Sashelp.Class;
Now use the SHOW NAMES statement to display all the matrices in the current SAS/IML session:
show names;
FigureĀ 7.11 shows that the READ statement
created three numeric vectors: Age
, Height
, and Weight
.
Notice, however, that FigureĀ 7.11 tells you that there are five symbols. The USE statement creates SAS/IML symbols for Name
and Sex
, but these variables were never read and so the symbols were not assigned values. (You can use the SHOW ALLNAMES statement
to see the unassigned symbols.) If the data set contains many variables, it can be more efficient to subset the data set by
using the VAR clause in the USE statement
. For example, the following statements create the same vectors but do not create symbols for the unread variables:
use Sashelp.Class var {Age Height Weight}; read all; close Sashelp.Class;