![]() Chapter Contents |
![]() Previous |
![]() Next |
| WHERE |
| Valid: | in DATA and PROC steps |
| Category: | Action |
| Type: | Declarative |
Syntax |
|
WHERE where-expression-1
< logical-operator where-expression-n>; |
| Tip: | The operands and operators described in the next several sections are also valid for the WHERE= data set option. |
| Tip: | You can specify multiple where-expressions. |
| Details |
WHERE statements can contain multiple WHERE expressions that are joined by logical operators.
SUBSTR requires the following arguments:
where substr(variable,position,length) ='character-string';An index is used in processing when the arguments of the SUBSTR function meet all of the following conditions:
You cannot use variables that are created within the DATA step (for example, FIRST.variable, LAST.variable, _N_, or variables that are created in assignment statements) in a WHERE expression because the WHERE statement is executed before the SAS System brings observations into the DATA or PROC step. When WHERE expressions contain comparisons, the unformatted values of variables are compared.
Use operands in WHERE statements as in the following examples:
You can include both SAS operators and special WHERE expression operators in the WHERE statement. For a complete list of the operators, see WHERE Statement Operators. For the rules SAS follows when it evaluates WHERE expressions, see "WHERE Processing" in SAS Language Reference: Concepts.
The caret (^), tilde (~), and the not sign (¬ ) all indicate a logical
not. Use the character available on your keyboard, or use the mnemonic equivalent.
The OR symbol
( | ), broken vertical bar ( | ), and exclamation point (!)
all indicate a logical or. Use the character available on your keyboard, or
use the mnemonic equivalent.
The caret (^),
tilde (~), and the not sign (¬ ) all indicate a logical not. Use the character
available on your keyboard, or use the mnemonic equivalent.
Two OR
symbols (| | ), two broken vertical bars ( | | ), or two exclamation points
(!!) indicate concatenation. Use the character available on your keyboard.
You can use the colon modifier (:) with any of the comparison operators. See SAS Operators for more information about the colon modifier.
| Comparisons |
| Examples |
This DATA step produces a SAS data set that contains
only observations from data set CUSTOMER in which the value for NAME begins
with
Mac and the value for CITY is
Charleston or
Atlanta.
data testmacs;
set customer;
where substr(name,1,3)='Mac' and
(city='Charleston' or city='Atlanta');
run;
where empnum between 500 and 1000;
where company ? 'bay'; where company contains 'bay';
where name is null; where name is missing;
where name like 'D%';
| Diana | |
| Diane | |
| Dianna | |
| Dianthus | |
| Dyan |
| WHERE Statement | Name Selected |
|---|---|
where name like 'D_an'; |
Dyan |
where name like 'D_an_'; |
Diana, Diane |
where name like 'D_an__'; |
Dianna |
where name like 'D_an%'; |
all names from list |
where lastname=*'Smith';
where year>1981; . . . more SAS statements . . . where same and year<1986;
In this example, the second WHERE statement is equivalent to the following WHERE statement:
where year>1981 and year<1986;
| See Also |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.