Sentry Page Protection
Proc SQL [1-15]
SELECT Statement
SELECT name
FROM school;
FROM school;
Proc SQL is often used to retrieve information from a SAS table.
Let's take a look at an example.
Copy and run the code from the yellow box below to get the SCHOOL table.
Proc SQL is often used to retrieve information from a SAS table.
Let's take a look at an example.
Copy and run the code from the yellow box below to get the SCHOOL table.
The SCHOOL table contains a list of students and their respective age, gender, school and height.
Now, we will retrieve just the students' name from the table using Proc SQL.
Example
Proc sql;
select name
from school;
quit;
select name
from school;
quit;
The list of students are retrieved and displayed in the output:
(try it on your SAS Studio!)
SELECT Statement
Let's go back to the code for a moment.
The Proc SQL step in our example contains a SELECT statement:
In this example, the SELECT statement has two clauses:
In this example, the SELECT statement has two clauses:
- SELECT Clause and
- FROM Clause
The SELECT clause selects the NAME column from the SAS table.
The FROM clause specifies the SCHOOL table as the source of data.
Unlike data step, the SQL procedure ends with the QUIT statement as opposed to the RUN statement.
Together with the SELECT clause and FROM clause, you can retrieve any columns from a SAS table.
Exercise
Locate the CARS table from the SASHelp library.
Write a Proc SQL step to retrieve the list of car models from the CARS table.
The car models are captured in the MODEL column.
Locate the CARS table from the SASHelp library.
Write a Proc SQL step to retrieve the list of car models from the CARS table.
The car models are captured in the MODEL column.
Need some help?
Fill out my online form.