Beruflich Dokumente
Kultur Dokumente
Datasets
Center of
Excellence
Objectives
Control which variables are written to an
output data set during a DATA step.
Control which variables are read from an
input data set during a DATA step.
Control how many observations are
processed from an input data set during a
DATA or PROC step.
Controlling Variable Output
By default, the SAS System writes all
variables from every input data set to
every output data set.
In the DATA step, the DROP and KEEP
statements can be used to control which
variables are written to output data sets.
The DROP and KEEP Statements
(Review)
Input SAS data set Raw data file
PDV
...
Creating Multiple SAS Data Sets
(Review)
proc contents data=prog2.military;
run;
Partial PROC CONTENTS Output
-----Alphabetic List of Variables and Attributes-----
PDV
...
Controlling Variable Output
set prog2.military;
if Type eq 'Army' then
output army;
else if Type eq 'Naval' then
output navy;
else if Type eq 'Air Force' then
output airforce;
else if Type eq 'Marine' then
output marines;
Controlling Variable Output
Partial Log
set prog2.military;
if Type eq 'Army' then
output army;
else if Type eq 'Naval' then
output navy;
else if Type eq 'Air Force' then
output airforce;
else if Type eq 'Marine' then
output marines;
Controlling Variable Output
Partial Log
...
Controlling Variable Input
Input SAS data set Raw Data File
PDV
...
Controlling Variable Input
SAS applies data set options to input data
sets before it
evaluates programming statements
applies data set options to output data sets.
PDV
...
prog2.military
TYPE CODE CITY STATE COUNTRY AIRPORT
$ $ $ $ $ $
9 3 20 2 3 40
PDV
TYPE CODE AIRPORT
$ $ $
9 3 40
...
prog2.military
TYPE CODE CITY STATE COUNTRY AIRPORT
$ $ $ $ $ $
9 3 20 2 3 40
PDV
TYPE CODE AIRPORT
$ $ $
D 9 3 40
...
Controlling Which Observations
Are Read
By default, SAS begins processing a SAS
data set with the first observation and
continues processing until the last
observation.
The FIRSTOBS= and OBS= data set
options can be used to control which
observations are processed.
You can use FIRSTOBS= and OBS= with
input data sets only. You cannot use
either data set option in the DATA
statement.
The OBS= Data Set Option
The OBS= data set option specifies an
ending point for processing an input data
set.
SAS-data-set(OBS=n)
SAS-data-set(OBS=n)
data army;
set prog2.military(obs=25);
if Type eq 'Army' then output;
run;
Controlling Which Observations
Are Read
Partial Log
60 data army;
61 set prog2.military(obs=25);
62 if Type eq 'Army' then output;
63 run;
67 data army;
68 set prog2.military(firstobs=11 obs=25);
69 if Type eq 'Army' then output;
70 run;
c02s3d1.sas
Questions