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 ...

Get APPLIED MULTIVARIATE STATISTICS: WITH SAS® SOFTWARE now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.