Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Proc SQL [1-14]


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.
Picture

Now, we will retrieve the list of student names from the table using Proc SQL.​
Picture

Example
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.
Picture

SAS will then display the list of student names in the output:
Picture

(Try it in 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:
Picture
​
The SELECT statement has two clauses:
  • SELECT clause and
  • FROM clause
Picture

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. ​​​​
Picture

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.
Next

Need some help? 


HINT:
The FROM clause is part of the SELECT statement. You do not need a semi-colon between the SELECT clause and the FROM clause.


SOLUTION:

proc sql;
select model
from sashelp.cars;
quit;


Fill out my online form.
Already a member? Go to member's area.