You can create a SAS data set from a matrix by using the CREATE statement with the FROM option. This form of the CREATE statement is as follows:
where
specifies the name of the new data set.
specifies the matrix that contains the data.
specifies names for the data set variables.
adds a character variable that identifies each row in the data set.
Suppose you want to create a SAS data set to contain a variable with the height-to-weight ratio for each student. The following
statements read variables from the Sashelp.Class
data set, form the ratio, and use the CREATE and APPEND statements to write a new SAS data set called Ratio
:
proc iml; use Sashelp.Class; read all var {Name Height Weight}; HWRatio = Height/Weight; create Ratio from HWRatio[colname="HtWt"]; append from HWRatio; show contents; close Ratio;
The variable in the Ratio
data set is called HtWt
. If you do not specify the COLNAME= option, the variables in the new data set are named COL1
, COL2
, and so forth.