Chapter 10
Acting on Selected Observations
Introduction to Acting on Selected Observations . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Selecting Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Understanding the Selection Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Selecting Observations Based on a Simple Condition . . . . . . . . . . . . . . . . . . . . . . 150
Providing an Alternative Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Creating a Series of Mutually Exclusive Conditions . . . . . . . . . . . . . . . . . . . . . . . 152
Constructing Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Understanding Construct Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Selecting an Observation Based on Simple Conditions . . . . . . . . . . . . . . . . . . . . . 155
Using More Than One Comparison in a Condition . . . . . . . . . . . . . . . . . . . . . . . . 155
Comparing Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Types of Character Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Comparing Uppercase and Lowercase Characters . . . . . . . . . . . . . . . . . . . . . . . . . 161
Selecting All Values That Begin with the Same Group of Characters . . . . . . . . . . 162
Selecting a Range of Character Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Finding a Value Anywhere within Another Character Value . . . . . . . . . . . . . . . . . 164
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Introduction to Acting on Selected Observations
Purpose
One of the most useful features of SAS is its ability to perform an action on only the
observations that you select. The following concepts are discussed in this section:
how the selection process works
how to write statements that select observations based on a condition
some special points about selecting numeric and character variables
147

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.