A.19. Creating a Matrix from a SAS Data Set

We can create a matrix out of a SAS data set. It is very helpful because many times after runnuing a SAS program, one may, for further calculations, need to use PROC IML. An example for the intended task is presented here. Suppose we have a data set called MYDATA with three variables X1, X2 and X3 and five data points, from which we want to create a matrix called MYMATRIX. To do so, we use the following SAS statements,

data mydata;
input x1 x2 x3;
lines;
2 4 8
3 9 1
9 4 8
1 1 1
2 7 8
;
proc iml;
use mydata;
read all into mymatrix;
print mymatrix;

If we want a matrix consisting of only a few variables, say in this case X3 and X1 (in that specific order) from the data set, then the appropriate READ statement needs to be slightly more specific as shown below.

read all var {x3 x1 into mymatrix;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.244