Working with SAS Data Sets


Make a SAS Data Set Current

The SAS/IML statements that process data operate on the current data set. It is therefore unnecessary to specify the data set as an operand to most statements. There are two current data sets, one for input and one for output. When you open a data set, it is set to be "current." You can also make a data set current by using the SETIN statement or the SETOUT statement . The following list summarizes the statements that change the current data set:

  • The USE and SETIN statements make a data set current for input.

  • The SETOUT statement makes a data set current for output.

  • The CREATE and EDIT statements make a data set current for both input and output.

The SHOW DATASETS statement displays which data sets are open and which are current for input and output.

The current observation is set by the last operation that performed input/output (I/O). If you want to set the current observation without doing any I/O, use the SETIN (or SETOUT) statement with the POINT option. After a data set is opened, the current observation is set to 0. If you attempt to list or read the current observation, the current observation is changed to 1. You can make the Sashelp.Class data set current for input and position the pointer at the tenth observation by using the following statements:

use Sashelp.Class;
setin Sashelp.Class point 10;

You can then read the tenth observation by using the READ statement, as follows:

read current var _NUM_ into x[colname=numVars];
read current var _CHAR_ into c[colname=charVars];
print x[colname=numVars], c[colname=charVars];

Figure 7.2: A Single Observation

x
Age Height Weight
12 59 99.5

c
Name Sex
John M