Sentry Page Protection
Proc SQL [2-14]
Selecting Multiple Columns
SELECT *
FROM school;
FROM school;
We have learned how to select a single column from a SAS table.
Now, we will look at how to retrieve multiple columns using Proc SQL.
[Reminder: if you haven't created the SCHOOL table, copy and run the code from the yellow box below in your SAS Studio.]
Selecting multiple columns is fairly easy.
You simply list the columns in the SELECT clause separated by a comma.
Example
Proc sql;
select Name, Age,
Gender
from school;
quit;
select Name, Age,
Gender
from school;
quit;
In this example, student name, age and gender are listed in the SELECT clause.
All three columns are retrieved and displayed in the output:
Note: each column is separated by a comma in the SELECT clause:
Selecting All Columns
You can also select all the columns by using the special character asterisk (*) in the SELECT clause.
Example
Proc sql;
select *
from school;
quit;
select *
from school;
quit;
The asterisk (*) tells SAS to select all of the columns from the SAS table.
All five columns from the SCHOOL table are displayed:
Exercise
Locate the CARS table from the SASHelp library.
Write a Proc SQL step to select the MAKE, MODEL and MSRP columns from the CARS table.
Locate the CARS table from the SASHelp library.
Write a Proc SQL step to select the MAKE, MODEL and MSRP columns from the CARS table.
Need some help?
HINT:
Simply list the three columns in the SELECT clause, separated by a comma.
SOLUTION:
Proc sql;
select make, model, msrp
from sashelp.cars;
quit;
Fill out my online form.