Reading, Combining, and Modifying 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; Total_Cost=AirCost+LandCost; Peak_Cost=(AirCost*1.15); Average_Night_Cost=LandCost/Nights; run;
Reading from Multiple SAS Data Sets |
You can read from multiple SAS data sets and combine and modify data in different ways. You can, 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.
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.
Task | Statements | Data Set Options | System Options | |
---|---|---|---|---|
Control variables | DROP | DROP= | ||
|
KEEP | KEEP= | ||
|
RENAME | RENAME= | ||
|
||||
Control observations | WHERE | WHERE= | FIRSTOBS= | |
|
subsetting IF | FIRSTOBS= | OBS= | |
|
DELETE | OBS= | ||
|
REMOVE | |||
|
OUTPUT | |||
|
Use statements or data set options (such as KEEP= and DROP=) to control the variables and observations 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.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.