| Working with SAS Data Sets |
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:
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).
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.