O'Reilly logo

Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11
Creating Subsets of Observations
Introduction to Creating Subsets of Observations . . . . . . . . . . . . . . . . . . . . . . . . . 169
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Selecting Observations for a New SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Deleting Observations Based on a Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Accepting Observations Based on a Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Comparing the DELETE and Subsetting IF Statements . . . . . . . . . . . . . . . . . . . . . 173
Conditionally Writing Observations to One or More SAS Data Sets . . . . . . . . . . 175
Understanding the OUTPUT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Example for Conditionally Writing Observations to Multiple Data Sets . . . . . . . . 175
Avoiding a Common Mistake When Writing to Multiple Data Sets . . . . . . . . . . . 176
Understanding Why the Placement of the OUTPUT Statement Is Important . . . . 177
Writing an Observation Multiple Times to One or More Data Sets . . . . . . . . . . . . 179
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Introduction to Creating Subsets of Observations
Purpose
In this section, you will learn to select specific observations from existing SAS data sets
to create new data sets. Specifically, you will learn about the following concepts:
how to create a new SAS data set that includes only some of the observations from
the input data source
how to create several new SAS data sets by writing observations from an input data
source, using a single DATA step
Prerequisites
Before proceeding with this section, you should understand the concepts presented in the
following sections:
169

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required