Working with SAS Data Sets


Overview

SAS/IML software has statements for creating a matrix from a SAS data set and for creating a SAS data set from a matrix.

You can create a matrix from a SAS data set in several ways. For example:

  • You can create a column vector for each data set variable.

  • You can create a matrix whose columns correspond to data set variables.

  • You can use all the observations in a data set or use a subset of them.

You can read observations from a SAS data set into a matrix. You can read them sequentially (by record number) or conditionally (by using a WHERE clause).

You can also create a SAS data set from a matrix. Each column of the matrix becomes a variable in the data set, and each row becomes an observation.

There are SAS/IML statements that enable you to edit, append, index, rename, and delete SAS data sets from within the SAS/IML environment.

You can dynamically specify which observations and variables are read. For example, the READ statement can do the following:

  • read all records

  • read the next record

  • read any number of specified records

  • read records that satisfy one or more conditions

  • read specified variables, all numeric variables, or all character variables

This chapter demonstrates how to use the SAS/IML language to do the following:

  • open a SAS data set

  • examine the contents of a SAS data set

  • display data values by using the LIST statement

  • read observations from a SAS data set into matrices or vectors

  • edit a SAS data set

  • create a SAS data set from a matrix or from vectors

  • produce summary statistics for variables in a data set

  • sort a SAS data set

  • index a SAS data set

The chapter also discusses similarities and differences between the data set and the SAS DATA step. All examples use the Sashelp.Class data set, which is distributed as part of SAS software. The Sashelp.Class data set contains data about 19 students. The variables are Name, Sex, Age, Height, and Weight.