Reading a SAS data set
refers to opening a SAS data set and bringing an observation into the program data
vector for processing.
Combining SAS data sets
refers to reading data from two or more SAS data sets and processing them by
one-to-one reading
one-to-one merging
updating a master data set with a transaction data set
The methods for combining SAS data sets are defined in “Combining SAS Data
Sets: Methods” on page 488.
Modifying SAS data sets
refers to using the MODIFY statement to update information in a SAS data set in
place. The MODIFY statement can save disk space because it modifies data in place,
without creating a copy of the data set. You can modify a SAS data set with
programming statements or with information that is stored in another data set.
Overview of Tools
The primary tools that are used for reading, combining, and modifying SAS data sets are
four statements: SET, MERGE, MODIFY, and UPDATE. This section describes these
tools and shows examples. For complete information about these statements, see the SAS
DATA Step Statements: Reference.
Reading SAS Data Sets
Reading a Single SAS Data Set
To read data from an existing SAS data set, use a SET statement. In this example, the
DATA step creates data set Perm.Tour155_PeakCost by reading data from data set
Perm.Tour155_Basic_Cost and by calculating values for the three new variables
Total_Cost, Peak_Cost, and Average_Night_Cost.
data perm.tour155_peakcost;
set perm.tour155_basic_cost;
476 Chapter 23 Reading, Combining, and Modifying SAS Data Sets
Reading from Multiple SAS Data Sets
You can read from multiple SAS data sets and combine and modify data in different
ways. For example, combine two or more input data sets to create one output data set,
merge data from two or more input data sets that share a common variable, and update a
master file based on transaction records.
For details about reading from multiple SAS data sets, see “Combining SAS Data Sets:
Methods” on page 488.
Controlling the Reading and Writing of Variables and Observations
If you do not instruct it to do otherwise, SAS writes all variables and all observations
from input data sets to output data sets. You can, however, control which variables and
observations you want to read and write by using SAS statements, data set options, and
functions. The statements and data set options that you can use are listed in the following
Table 23.1 Statements and Options That Control Reading and Writing
Task Statements Data Set Options System Options
Control variables DROP DROP=
Control observations WHERE WHERE= FIRSTOBS=
subsetting IF FIRSTOBS= OBS=
Use statements or data set options (such as KEEP= and DROP=) to control the variables
and observations that you want to write to the output data set. The WHERE statement is
an exception: it controls which observations are read into the program data vector based
on the value of a variable. You can use data set options (including WHERE=) on input or
output data sets, depending on their function and what you want to control. You can also
use SAS system options to control your data.
Reading SAS Data Sets 477

Get SAS 9.4 Language Reference, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.