You are on page 1of 14

Creating Subsets

of Observations
You will Learn:

• Creating a new data having only a sub-set of


observations

• Creating more than one data sets from a single data set
Reading materials

Chapter 10. Acting on selected observations. Step-by-Step


Programming with Base SAS® 9.4, Second Edition
Copyright © 2015, SAS Institute Inc., Cary, NC, USA
Input SAS Data set for Examples
Selecting Observations for a New SAS Data Set

Syntax:
IF condition THEN DELETE;
Accepting Observations Based on a Conditions
Comparing the DELETE and Subsetting IF Statements

Method 1: Delete the unwanted observation


Comparing DELETE and Subsetting IF Statements

Method 2 (safer): accept the observation you want


Conditionally Writing Observations to One or more SAS Data
Sets

Output statement
Syntax:
Output <SAS-data-set(s)>;

Output Statement
Understanding the OUTPUT Statement

Lucastour

Othertours

Other Guides
A Common Mistake When Writing to Multiple Data Sets
Understanding Why the Placement of OUTPUT Statement Is
Important

Output statement causes observation to be written to data set


Assignment statement NOT executed because obs already output

The observation
was output
BEFORE the
assignment
statement could be
executed
missing values
generated
The Correct Way

Assignment statements must come before output statements


Writing an Observation Multiple Times to One or
More Data Sets
Writing an Observation Multiple Times to One or More Data Sets

You might also like