Accessing SAS Data Sets in IML

Contents Index <<Browse<< >>Browse>>


It is easy to either read a SAS data set into a matrix or turn a matrix into a SAS data set. Keep in mind that matrices must contain either numeric or character variables but not both.

All the numeric variables in the SAS data set class are read into a matrix m with the commands

use class;
read all var _num_ into m;
close class;

The use statement opens a SAS data set for read access. The data set can have either a one or two level name. More than one data set can be open at the same time. Data sets should be closee when not immediately needed.

The read statement reads the values from the data set. The var _num_ option specifies that all numeric variables are used as columns of the matrix m. (This is the default selection and may be omitted from the command.) Other options are var _char_ for all character variables, var _all_ for all variables, and var {height age} to read only the variables height and age into the matrix.

The close statement closes the SAS dataset.

The invocation

use class;
read all;
close class;

creates a column vector for each variable in the SAS data set. The name of each vector is the name of the corresponding variable in the data set.

The commands

create class from m [colname={'height' 'age'}];
append from m;
close class;

creates a SAS data set class from the matrix m and assigns height and age as the names of the variables associated with the columns of m.

For further information see the online help under HELP--SAS SYSTEM--MODELING AND ANALYSIS TOOLS--INTERACTIVE MATRIX LANGUAGE or Chapter 6 of SAS/IML Software.


Contents Index <<Browse<< >>Browse>>

Copyright © 1997 by Jerry Alan Veeh. All rights reserved.