Sentry Page Protection
Proc SQL [5-14]
WHERE Clause
SELECT *
FROM school
WHERE height < 60;
FROM school
WHERE height < 60;
By default, Proc SQL retrieves all of the rows from the table.
The WHERE clause allows you to retrieve only a subset of rows.
Copy and run the SCHOOL table from the yellow box below if you haven't done so.
Example
Proc sql;
select *
from school
where height < 60;
quit;
select *
from school
where height < 60;
quit;
The WHERE clause in this example selects only the students who are shorter than 60 inches.
A subset containing these students is displayed:
(Try it in your SAS Studio!)
Let's take a look at another example.
Proc sql;
select *
from school
where gender = 'M';
quit;
select *
from school
where gender = 'M';
quit;
In this example, the WHERE clause selects only the male students from the SCHOOL table.
BETWEEN-AND Operator
You can use the BETWEEN-AND operator to select rows that fall within a specific range.
Example
Proc sql;
select *
from school
where age
between 14 and 15;
quit;
select *
from school
where age
between 14 and 15;
quit;
The WHERE clause in this example selects only the students who are between 14 and 15 years old.
Exercise
Locate the SHOES table from the SASHelp library.
Write a Proc SQL step to display the shoes sales that are between $200,000 to $300,000.
The shoes sales data is captured in the SALES column. Display all of the columns from the SHOES table.
Locate the SHOES table from the SASHelp library.
Write a Proc SQL step to display the shoes sales that are between $200,000 to $300,000.
The shoes sales data is captured in the SALES column. Display all of the columns from the SHOES table.
Need some help?
HINT:
Use the between-and operator to select rows where the sales are between the specified range.
SOLUTION:
Proc sql;
select *
from sashelp.shoes
where sales between 200000 and 300000;
quit;
Fill out my online form.