Retrieve column(s) from table
SELECT name 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.
The SCHOOL table contains a list of students and their respective age, gender, school and height.
Now, we will retrieve the list of student names from the table using Proc SQL.
Proc sql; select name from school; quit;
Proc SQL is fairly simple and straightforward.
In order to retrieve the NAME column from the SCHOOL table, you simply tell SAS to select the NAME column from the SCHOOL table.
SAS will then display the list of student names in the output:
(Try it in your SAS Studio!)
Let's go back to the code for a moment.
The Proc SQL step in our example contains a SELECT statement:
The SELECT statement has two clauses:
The SELECT clause selects the NAME column from the SAS table.
The FROM clause specifies the SCHOOL table as the source of the 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.
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?
The FROM clause is part of the SELECT statement. You do not need a semi-colon between the SELECT clause and the FROM clause.