Selecting Multiple Columns
SELECT *
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;
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;
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.
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;
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |