This preview shows page 1. Sign up to view the full content.
Unformatted text preview: S option:
PROC PRINT DATA=SAS-data-set NOOBS;
RUN; The SAS System
ID Salary PILOT
21957.71 9 10
c04s1d3 Subsetting Data: WHERE
Statement Subsetting Data: WHERE Statement
General form of the WHERE statement: The WHERE statement
• enables you to select observations that meet
a certain condition
• can be used with most SAS procedures. WHERE where-expression; • where-expression is a sequence of
operands and operators. Example:
Produce a listing report that displays information
for pilots only. • Operands include
11 12 3 Comparison Operators Subsetting Data: WHERE Statement Mnemonic Symbol Definition EQ
NE GT < GE >= greater than or equal to LE –comparison operators
> LT • Operators include = <= less than or equal to IN equal to
not equal to greater than
less than equal to one of a list 13 Comparison Operators 14 Logical Operators Examples: AND
if both expressions are true, then the
compound expression is true
where JobCode='FLTAT' and Salary>50000; where Salary>25000;
where Salary=.; OR
if either expression is true, then the
compound expression is true
where JobCode='PILOT' or JobCode='FLTAT'; where LastName=' ';
where JobCode in('PILOT','FLTAT');
where JobCode in('PILOT' 'FLTAT');
Character comparisons are case-sensitive.
The IN operator allows commas or blanks to separate
can be combined with other operators
to reverse the logic of a comparison.
where JobCode not in ('PILOT','FLTAT');
15 16 4 Special Operators
BETWEEN-AND Special Operators
Additional special operators supported by
the WHERE statement are
• =* (i.e., sounds like)
• IS MISSING (or IS NULL). selects observations in which the
value of the variable falls within a
range of values, inclusively. where Salary between 50000 and 70000;
selects observations that include
the specified substring.
where LastName ? 'LAM';
(LAMBERT, BELLAMY, and ELAM are selected.)
17 Special Operators 18 Special Operators The following are special operators :
• LIKE selects observations by comparing character
values to specified patterns.
A percent sign (%) replaces any number of
An underscore (_) replaces one character. • The sounds like (=*) operator selects
observations that contain spelling variations of
the word or words specified.
where Name=*'SMITH'; Selects names like SMYTHE and SMITT.
• IS NULL or IS MISSING selects observations in
which the value of the variable is missing. where Code like 'E_U%';
Selects observations where the value of Code begins
with an E, followed by a single character, followed by
a U, followed by any number of characters. where Flight is missing;
where Flight is null;
19 20 5 Printing Selected Observations Subsetting Data: Data Set Options Use the WHERE statement to control which observations are processed.
EmpID LastName 0031 GOLDE...
View Full Document
This note was uploaded on 09/25/2013 for the course STAT 440 taught by Professor Muyot,m during the Fall '08 term at University of Illinois, Urbana Champaign.
- Fall '08