Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Working with SAS Data Sets

Using the CREATE Statement with the FROM Option

You can create a SAS data set from a matrix using the CREATE statement with the FROM option. This form of the CREATE statement is

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 containing the data.

column-name
names the variables in the data set.

row-name
adds a variable containing row titles to the data set.

Suppose you want to create a SAS data set named RATIO containing a variable with the height-to-weight ratios for each student. You first create a matrix containing 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).

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.