Using the CREATE Statement with the FROM Option

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:

CREATE SAS-data-set FROM matrix ;
<[COLNAME=column-name ROWNAME=row-name]> ;

where

SAS-data-set

names the new data set.

matrix

names the matrix that contains the data.

column-name

names the variables in the data set.

row-name

adds a variable that contains row titles to the data set.

Suppose you want to create a SAS data set named RATIO that contains a variable with the height-to-weight ratios for each student. You first create a matrix that contains the ratios from the matrices HEIGHT and WEIGHT that you have already defined. Next, use the CREATE and APPEND statements to open a new SAS data set called RATIO and append the observations, naming the data set variable HTWT instead of COL1.

   htwt=height/weight;
   create ratio from htwt[colname='htwt'];
   append from htwt;

Now submit the SHOW DATASETS and SHOW CONTENTS statements:

   > show datasets;

     LIBNAME MEMNAME   OPEN MODE   STATUS
     ------- -------   ---------   ------
     WORK    .CLASS    Update
     WORK    .RATIO    Update      Current Input    Current Output

   > show contents;

     VAR NAME   TYPE   SIZE
     HTWT       NUM      8
     Number of Variables:    1
     Number of Observations: 18

   > close ratio;

As you can see, the new SAS data set RATIO has been created. It has 18 observations and 1 variable (recall that you deleted 1 observation earlier).