Professional Documents
Culture Documents
Essentials
Lesson Quizzes
SAS and all other SAS Institute Inc. product or service names are registered trademarks or
trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other
brand and product names are trademarks of their respective companies.
Copyright © 2019 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United
States of America. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise,
without the prior written permission of the publisher, SAS Institute Inc.
Book code E714091, course code SQ1M6LQ, prepared date 11Dec2019. SQ1M6LQ_001
Lesson 1 Lesson Quizzes
1.1 Quizzes........................................................................................................................ 1-3
Lesson 1 – Essentials.............................................................................................. 1-3
Lesson 2 – PROC SQL Fundamentals ....................................................................... 1-8
Lesson 3 – SQL Joins............................................................................................ 1-16
Lesson 4 – Subqueries .......................................................................................... 1-21
Lesson 5 – Set Operators....................................................................................... 1-26
Lesson 6 – Using and Creating Macro Variables in SQL.............................................. 1-31
Lesson 7 – Accessing DBMS Data with SAS/ACCESS ............................................... 1-36
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-3
1.1 Quizzes
Lesson 1 – Essentials
1. You want to explore the first 10 rows of the sq.profit table. Which PROC
SQL option limits the rows from the sq.profit table that contribute to
the query?
a. OUTOBS=10
b. OBS=10
c. ROW=10
d. INOBS=10
3
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
2. When using only the SQL procedure, you can create which of the
following objects?
a. SAS tables
b. SAS views
c. DBMS tables
d. all of the above
5
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-4
3. You want to display the column name, column types, and other column
information from the sq.profit table. Which statement should you use?
a. content sq.profit;
b. contents table sq.profit;
c. describe sq.profit;
d. describe table sq.profit;
7
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
4. Which PROC SQL option would you use to produce a report that includes
the row number in the report?
a. NUMBER
b. OBS
c. ROWNUM
d. ROW
9
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-5
a. SELECT ALL
b. SELECT _COLUMNS_
c. SELECT *
d. SELECT _ALL_
11
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. true
b. false
13
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-6
7. You want to produce a report that selects the Make, Model, and
MPG_City columns from the sashelp.cars table. Which of the following
queries is correct?
a. select Make, Model, MPG_City
from sashelp.cars;
b.
select Make Model MPG_City
from sashelp.cars;
c.
from sashelp.cars
select Make Model MPG_City;
d. from sashelp.cars
select Make, Model, MPG_City;
15
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. First_Name, Last_Name
b. Last_Name, First_Name
c. Last_Name, First_Name, Job_Title
17
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-7
9. In your PROC SQL code, you can include SAS features that do not
conform to the ANSI standard.
a. true
b. false
19
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
21
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-8
1. Which SELECT statement creates a report that displays only the unique
combinations of Customer_Type_ID and Country?
a. select distinct Customer_Type_ID Country
from orion.customer;
24
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
26
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-9
b. Employee Number
c. Label='Employee ID'
28
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
b. Bonus=Salary*.03
d. Salary*.03 Bonus
30
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-10
5. To guarantee the order of the rows in the output, you must use an
ORDER BY clause.
a. true
b. false
32
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
6. If the values returned by the YEAR function are . (missing), 2018, 2019,
and 2020, which value for year is displayed first in the output based on
this code?
proc sql;
select Employee_ID, Employee_Term_Date format=date9.,
year(Employee_Term_Date) as year
from orion.employee_payroll
where Employee_Gender='M' and Marital_Status='S'
order by year;
quit;
a. . (missing)
b. 2018
c. 2019
d. 2020 34
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-11
36
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
b. case
when 20 <= Age <= 29 then '20-29';
38
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-12
9. In this PROC SQL program, the two SELECT statements use the
orion.employee_donations table and generate the same results.
40
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
10. The product_dim table contains 481 rows—that is, 1 row for each
product that Orion Star sells. All Orion Star products are assigned to
1 of 50 product groups. Which SELECT statement creates a report
that shows the number of products in each product group?
a. select Product_Group, count(*) as Products
from orion.product_dim;
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-13
11. To produce a report that includes all Toyotas with a Price value less than
$30,000, which WHERE clause would you use?
Make Model Price MPG
Toyota RAV4 $28,750 23
Honda Accord $19,350 32
Honda Pilot $32,500 22
BMW 135i $25,200 24
12. In which of the following queries can you replace the SAS summary
function MEAN with the ANSI summary function AVG and get the
same results?
a. select mean(Qtr1, Qtr2, Qtr3, Qtr4) as Mean_Annual
from orion.employee_donations;
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-14
13. You want to count the number of employees in each department and
return only the departments with more than 30 employees. Which
query produces the correct report?
a. select Department, count(*) as TotalEmployees
from orion.employees
where calculated TotalEmployees > 30
group by Department;
14. Which of the following statements creates a new table named results
from a query?
a. create table results like
select ...
50
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-15
15. Which of the following queries produces a report of all columns from
every table in the Sashelp library?
a. select *
from dictionaries.columns
where libname="SASHELP";
b. select *
from sashelp.vcolumn
where libname="SASHELP";
c. select *
from dictionary.columns
where libname="SASHELP";
52
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-16
1. How many rows does the following query produce in the report?
select *
from sq.employee_donations,
sq.employees;
a. 4 employee_donations employees
b. 5 Employee_ID Qtr1 Qtr2 Qtr3 Qtr4 Employee_ID Name
c. 9 120265 . . . 25 120265 Panagiotis
d. 20 120267 15 15 15 15 120267 Emma
120269 20 20 20 20 120269 Fatima
120270 20 10 5 . 120270 Sofia
120272 Owen
55
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
c. select *
120265 Panagiotis
from employee_donations as d inner join 120267 Emma
employees as e
on d.Employee_ID=e.Employee_ID; 120269 Fatima
120270 Sofia
57 120272 Owen
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-17
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-18
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-19
8. Which query joins the tables group1 and group2 and overlays the Tag
columns to produce the result set shown below? group1 group2
Tag FName Tag LName
select g1.Tag
a. from group1 as g1 a Fred b Zhou
group2 as g2 d Sek c Amos
where g1.Tag=g2.Tag
e Lars
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-20
widgets locations
9. The widgets table stores information about the
ID Type ID Bin
most popular items sold in a hardware store.
89 FL 1 B98
The locations table stores information about the
46 UI 46 B63
location of some of the items in the store. Which
47 TA 74 B02
query produces the result set that is shown below?
92 QY 85 B98
a. select coalesce(w.ID, I.ID) as ID, Type, Bin 99 B02
from widgets as w left join locations as I
on w.ID = I.ID Results
order by w.ID;
ID Type Bin
71
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
73
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-21
Lesson 4 – Subqueries
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-22
80
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
b.
select ID, Job_Title, Salary
from staff
where ID = (select ID from staff where Department ="Engineering");
82
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-23
a. true
b. false
84
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
6. Suppose you need to use the most up-to-date data from a complex
query and want multiple users to be able access the information. Which
of the following solutions would be best?
a. Create a table with the complex query and allow users access to
the table.
b. Create a view with the complex query and allow users to access the
view.
c. Send users the complex query to copy and paste in their queries as
an in-line view.
86
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-24
88
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. using a one-level name for the source table in the FROM clause in
the view definition, and storing the view in a different location as
the source table
b. using a two-level name for the source table in the FROM clause in
the view definition, and storing the view in the different location as
the source table
c. embedding the LIBNAME statement with a USING clause when
creating the view
90
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-25
9. Before you run this query, which of the following changes can you make
to prevent SAS from remerging, and still produce a report?
select Order_Type,
min(Quantity) label="Min Qty"
from orion.order_fact;
92
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
inventory Results
10. Which SELECT clause calculates the Product Quantity Product Pct
total percentage of inventory for Shirt 5 Shirt 50%
each product? Shoes 3 Shoes 30%
Pants 2 Pants 20%
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-26
proc sql;
a b
select * ID Pet ID Pet
from a 1 Cat 1 Cat
intersect
select * 1 Dog 2 Cow
from b; 1 Pig 3 Dog
quit;
a. 1
b. 2
c. 5
d. 6
97
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. true
b. false
99
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-27
a. 1
b. 2
c. 5
d. 6
101
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
4. Adding the CORR and ALL keywords to the EXCEPT operator would
change the number of rows that this query produces.
a b
proc sql;
select * ID Pet ID Pet
from a 1 Cat 1 Cat
except
select * 1 Dog 2 Cow
from b; 1 Pig 3 Dog
quit;
a. true
b. false
103
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-28
a. 1
b. 2
c. 5
d. 6
105
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. 2
b. 3
c. 4
d. 5
107
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-29
a. 2
b. 4
c. 6
d. 8
109
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. When used with the EXCEPT operator, the CORR keyword instructs
PROC SQL to position by same-name columns and eliminate
columns that do not have the same name in both tables from the
final results.
b. When used with the INTERSECT operator, the CORR keyword
instructs PROC SQL to overlay columns by position in the final
results.
c. When used with the OUTER UNION operator, the CORR keyword
instructs PROC SQL to eliminate columns that do not have the same
name in both tables from the final results.
111
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-30
113
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
10. PROC SQL with set operators handles columns and rows, depending on
the specific set operator and keywords used in the set operation.
a. true
b. false
115
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-31
a. 9.2
b. 10:32
c. 1352050
d. Soccerballs
e. all of the above
118
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
120
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-32
3. Which of the following options enables you to view the values of the
macro variables without using them in a report?
122
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. %user path=s:/workshop/data;
b. %macro path=s:/workshop/data;
c. %path=s:/workshop/data;
d. %let path=s:/workshop/data;
124
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-33
5. Which of these queries places one value from the first row returned by
the SQL query into a macro variable?
a. select avg(Salary)
into :MeanSalary
from store.employee;
b. select avg(Salary)
into %MeanSalary
from store.employee;
c. select avg(Salary)
into &MeanSalary
from store.employee;
126
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. put &=MeanSalary;
b. put MeanSalary;
c. %put &=MeanSalary;
d. %put MeanSalary;
128
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-34
7. You want to store the descriptive statistics of the Price column from the
inventory table into multiple macro variables. Which query successfully
stores mean, median, min, and max?
a. select mean(Price), median(Price), min(msrp), max(Price)
into: MeanPrice, MedianPrice, MinPrice, MaxPrice
from inventory;
130
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
c. select Product
into :InventoryList separated by ","
from inventory;
132
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-35
9. Given the table revenue below, you want to store the sum of Revenue
in a macro variable named TotalRevenue. Does the following query
store the exact value of 900000000 in TotalRevenue?
revenue
proc sql; Product Revenue
select sum(Revenue) Shirt $200,000,000
into :TotalRevenue
from revenue; Shoes $300,000,000
quit; Pants $400,000,000
a. yes
b. no
134
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
10. Given the table revenue below, you want to store the sum of Revenue
in a macro variable named TotalRevenue. Which of the following
queries stores the exact value of $900,000,000 in the macro variable
TotalRevenue?
revenue
a. select sum(Revenue) format=dollar16. Product Revenue
into :TotalRevenue
from revenue; Shirt $200,000,000
Shoes $300,000,000
b. select sum(Revenue) Pants $400,000,000
into :TotalRevenue format=dollar16.
from revenue;
c. select sum(Revenue)
into :TotalRevenue
from revenue; 136
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-36
a. true
b. false
139
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
2. You're familiar with the Oracle SQL implementation. You begin to use
PROC SQL but don't want to learn any of the SAS enhancements and
functions. You would like to continue to use the Oracle SQL
implementation inside SAS. Which method would you use to interact
with the Oracle database?
141
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-37
3. You're familiar with using PROC SQL and are connecting to an SQL
Server database. You are not familiar with the database implementation
of SQL and want to continue using PROC SQL. Which method would you
use to interact with the SQL Server database?
143
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
a. proc fedsql;
select EmployeeID, Name, Salary, Department
from orion.employee
where = "Management";
quit;
b. proc fedsql;
select EmployeeID, Name, Salary, Department
from orion.employee
where = 'Management';
quit;
145
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-38
5. You are working with an Oracle database and want to push as much of
the processing as possible into the database. Which PROC would be
better to use?
a. PROC SQL
b. PROC FEDSQL
147
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-39
1.2 Solutions
Lesson 1
1. You want to explore the first 10 rows of the sq.profit table. Which PROC
SQL option limits the rows from the sq.profit table that contribute to
the query?
a. OUTOBS=10
b. OBS=10
c. ROW=10
d. INOBS=10
4
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The INOBS= option restricts the number of rows that PROC SQL reads from all tables specified in
the FROM clause. The OUTOBS= option restricts the number of rows that a query outputs. The
OBS= option is a SAS data set option that is used in the FROM clause to l imit the number of rows
from a table.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-40
2. When using only the SQL procedure, you can create which of the
following objects?
a. SAS tables
b. SAS views
c. DBMS tables
d. all of the above
6
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
As output, a PROC SQL query creates a report by default. However, a PROC SQL query can also
create SAS tables, SAS or DBMS views, and DBMS tables.
3. You want to display the column name, column types, and other column
information from the sq.profit table. Which statement should you use?
a. content sq.profit;
b. contents table sq.profit;
c. describe sq.profit;
d. describe table sq.profit;
8
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
You specify the DESCRIBE TABLE statement and then the name of the t able to describe.
DESCRIBE TABLE generates a description of the table in the log. Results display the column
names, column types, and associated labels or formats, if they exist, for specific columns.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-41
4. Which PROC SQL option would you use to produce a report that includes
the row number in the report?
a. NUMBER
b. OBS
c. ROWNUM
d. ROW
10
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The NUMBER option specifies whether the SELECT statement includes the row number of the data
as the rows are retrieved.
a. SELECT ALL
b. SELECT _COLUMNS_
c. SELECT *
d. SELECT _ALL_
12
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The asterisk (*) represents all columns of the table or tables listed in the FROM clause.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-42
a. true
b. false
14
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Although SQL has a set of standards, it is important to understand that database management
systems offer different implementations of the standard SQL. Database management systems like
Oracle, Teradata, SQL Server, Postgres, and a variety of others all follow ANSI standard SQL.
However, some might have keywords, features, and enhancements that are slightly different
between systems.
7. You want to produce a report that selects the Make, Model, and
MPG_City columns from the sashelp.cars table. Which of the following
queries is correct?
a. select Make, Model, MPG_City
from sashelp.cars;
b.
select Make Model MPG_City
from sashelp.cars;
c.
from sashelp.cars
select Make Model MPG_City;
d. from sashelp.cars
select Make, Model, MPG_City;
16
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
You specify the names of the columns, separated by commas, in the SELECT clause, and specify
the input table in the FROM clause.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-43
a. First_Name, Last_Name
b. Last_Name, First_Name
c. Last_Name, First_Name, Job_Title
18
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
In a query’s output, the columns appear in the order in which they are listed in the SELECT clause.
Columns that are listed in other clauses, but not the SELECT clause, do not appear in output.
9. In your PROC SQL code, you can include SAS features that do not
conform to the ANSI standard.
a. true
b. false
20
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
In PROC SQL, you can include SAS enhancements that go beyond the ANSI standard.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-44
22
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
If present, the clauses must be in this order: SELECT, FROM, WHERE, GROUP BY, HAVING, and
ORDER BY, but not all clauses must be present. For example, you can use the WHERE clause and
ORDER BY clause and not use the GROUP BY or HAVING clause.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-45
Lesson 2
1. Which SELECT statement creates a report that displays only the unique
combinations of Customer_Type_ID and Country?
a. select distinct Customer_Type_ID Country
from orion.customer;
25
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To select unique combinations of the values of multiple columns, you place the DISTINCT keyword
once in the SELECT clause before the entire column list. Columns must be separated by commas.
27
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The SAS keyword CALCULATED enables you to use the results of an expression in the same
SELECT clause or in the WHERE clause.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-46
b. Employee Number
c. Label='Employee ID'
29
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The LABEL= column modifier is not ANSI standard. It is a SAS enhancement to specify labels. You
can use the ANSI column modifier, the LABEL= column modifier, or both within the same SELECT
clause.
b. Bonus=Salary*.03
d. Salary*.03 Bonus
31
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
An equal sign is not allowed in the expression in the SELECT clause when creating a new column.
To assign a name that is referred to as an alias in PROC SQL, use the keyword AS followed by a
valid SAS name, not the expression.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-47
5. To guarantee the order of the rows in the output, you must use an
ORDER BY clause.
a. true
b. false
33
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To guarantee the order of the rows in the output, you must use an ORDER BY clause.
6. If the values returned by the YEAR function are . (missing), 2018, 2019,
and 2020, which value for year is displayed first in the output based on
this code?
proc sql;
select Employee_ID, Employee_Term_Date format=date9.,
year(Employee_Term_Date) as year
from orion.employee_payroll
where Employee_Gender='M' and Marital_Status='S'
order by year;
quit;
a. . (missing)
b. 2018
c. 2019
d. 2020 35
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The default of the ORDER BY clause specifies to display values from the smallest to the largest
numeric or character value. PROC SQL treats null or missing values as the smallest possible value.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-48
37
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
You must place TITLE and FOOTNOTE statements before the SELECT clause, because in the SQL
procedure the SELECT clause runs immediately. Alternatively, you can place the statements before
the PROC SQL statement.
b. case
when 20 <= Age <= 29 then '20-29';
39
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
When you need to use a comparison operator other than equal, you use a simple case expression.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-49
9. In this PROC SQL program, the two SELECT statements use the
orion.employee_donations table and generate the same results.
41
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
COUNT(*) counts the total number of rows in a table or in a subset. However, when you specify a
column as an argument for COUNT, the function counts the number of rows in the table or in a
subset that have a nonmissing value for that column.
10. The product_dim table contains 481 rows—that is, 1 row for each
product that Orion Star sells. All Orion Star products are assigned to
1 of 50 product groups. Which SELECT statement creates a report
that shows the number of products in each product group?
a. select Product_Group, count(*) as Products
from orion.product_dim;
To aggregate summary statistics by the values of the non-summarized column, Product_Group, the
query must use a GROUP BY clause that specifies the Product_Group column. This report is
grouped by only one column. Also, the GROUP BY clause cannot specify a summarized column, like
Products.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-50
11. To produce a report that includes all Toyotas with a Price value less than
$30,000, which WHERE clause would you use?
Make Model Price MPG
Toyota RAV4 $28,750 23
Honda Accord $19,350 32
Honda Pilot $32,500 22
BMW 135i $25,200 24
To select all rows where Make equals Toyota and Price is less than 30000, you must use the AND
operator. Toyota must be in quotation marks and is case sensitive, and the numeric Price value must
be in standard numeric form.
12. In which of the following queries can you replace the SAS summary
function MEAN with the ANSI summary function AVG and get the
same results?
a. select mean(Qtr1, Qtr2, Qtr3, Qtr4) as Mean_Annual
from orion.employee_donations;
Unlike most SAS summary functions, ANSI summary functions can take only a single argument.
Also, because PROC SQL is ANSI standard, shortcuts to reference a range of variables in an
argument list within a function are not acceptable in PROC SQL as they are in other SAS
procedures.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-51
13. You want to count the number of employees in each department and
return only the departments with more than 30 employees. Which
query produces the correct report?
a. select Department, count(*) as TotalEmployees
from orion.employees
where calculated TotalEmployees > 30
group by Department;
The WHERE clause is evaluated before a row is available for processing and determines which
individual rows are available for grouping. You cannot use a WHERE clause to subset grouped rows
by referring to the calculated summary column.
You must use the HAVING clause with a GROUP BY clause to filter summarized rows. The HAVING
clause affects groups in a way that is similar to how a WHERE clause affects indiv idual rows. When
you use a HAVING clause, PROC SQL displays only the groups that satisfy the HAVING expression.
PROC SQL applies the HAVING condition after grouping the data and applying aggregate functions.
Think of the HAVING clause as post-summarization filtering.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-52
14. Which of the following statements creates a new table named results
from a query?
a. create table results like
select ...
51
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To create a table from a query result, you use a CREATE TABLE statement with the new table name
and the AS keyword followed by the query. Adding CREATE TABLE at the beginning of the query
creates a table instead of results from the query.
15. Which of the following queries produces a report of all columns from
every table in the Sashelp library?
a. select *
from dictionaries.columns
where libname="SASHELP";
b. select *
from sashelp.vcolumn
where libname="SASHELP";
c. select *
from dictionary.columns
where libname="SASHELP";
53
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The columns DICTIONARY table shows all columns in every table. The WHERE clause limits the
report to all tables in the Sashelp library. All library values are stored in uppercase. The
SASHELP.VCOLUMN table produces the same report when using the PRINT procedure.
SASHELP.VCOLUMN does not work in PROC SQL.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-53
Lesson 3
1. How many rows does the following query produce in the report?
select *
from sq.employee_donations,
sq.employees;
a. 4 employee_donations employees
b. 5 Employee_ID Qtr1 Qtr2 Qtr3 Qtr4 Employee_ID Name
c. 9 120265 . . . 25 120265 Panagiotis
d. 20 120267 15 15 15 15 120267 Emma
120269 20 20 20 20 120269 Fatima
120270 20 10 5 . 120270 Sofia
120272 Owen
56
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The default join combines every row in each table. This is called the Cartesian product. Typically, the
Cartesian product is not the desired result. In this example, all 4 rows from the
employee_donations table are joined with every row in the employees table. The new report
contains 20 rows.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-54
c. select *
120265 Panagiotis
from employee_donations as d inner join 120267 Emma
employees as e
on d.Employee_ID=e.Employee_ID; 120269 Fatima
120270 Sofia
58 120272 Owen
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
In the FROM clause, you specify the first table and the keywords INNER JOIN, followed by the
second table. Following the table names and join type, the syntax requires an ON clause to describe
the join criteria for matching rows in the tables. When you refer to tables that have a same-named
column, you must qualify the column names to specify the location of each column.
To display an expanded query, which contains a list of qualified column names in the SAS log, you
add the FEEDBACK option to the PROC SQL statement above the SELECT statement.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-55
The SELECT clause qualifies the Prod_ID column name, so the result set has only one Prod_ID
column. This is an inner join, so the ON clause joins only the rows that have the matching values of
Prod_ID and the Color Blue.
Most database products treat missing values as the absence of a value (nulls), and because they
don't contain any value, they're excluded from any conditional evaluation. PROC SQL treats missing
values as valid values and matches for joins. Any missing value matches with any other missing
value of the same type (character or numeric) in a join. This could return unexpected results.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-56
In the ON clause, you can use comparison operators instead of equality for the JOIN criteria. The
p.Price column must be greater than or equal to the t.Low value, and less than or equal to the
t.High value for the row to join.
A left join lists every item in the left table (products) with or without a match in the right table
(saleitems).
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-57
8. Which query joins the tables group1 and group2 and overlays the Tag
columns to produce the result set shown below? group1 group2
Tag FName Tag LName
select g1.Tag
a. from group1 as g1 a Fred b Zhou
group2 as g2 d Sek c Amos
where g1.Tag=g2.Tag
e Lars
The full join with the COALESCE function creates this result set. To overlay two columns, you must
specify the two columns as arguments in the COALESCE function.
widgets locations
9. The widgets table stores information about the
ID Type ID Bin
most popular items sold in a hardware store.
89 FL 1 B98
The locations table stores information about the
46 UI 46 B63
location of some of the items in the store. Which
47 TA 74 B02
query produces the result set that is shown below?
92 QY 85 B98
a. select coalesce(w.ID, I.ID) as ID, Type, Bin 99 B02
from widgets as w left join locations as I
on w.ID = I.ID Results
order by w.ID;
ID Type Bin
72
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
This result set contains all the rows from the widgets table and only the matching row from the
locations table. A left join that specifies the widgets table as the left, or first, table can create these
results. A right join can create this result set only if the widgets table is specified as the right, or
second, table.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-58
74
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To write a self-join, select from the same table listed twice with different aliases . Set up the join type
and then the matching criteria referencing the table alias.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-59
Lesson 4
A noncorrelated subquery must be a valid query inside parentheses in the WHERE or HAVING
clause, and return a single column with one or more rows.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-60
81
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
A noncorrelated subquery can be extracted and run independently of the outer query.
b.
select ID, Job_Title, Salary
from staff
where ID = (select ID from staff where Department ="Engineering");
83
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The IN operator is required in the WHERE clause because it can accept multiple values from the
subquery.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-61
a. true
b. false
85
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
An in-line view acts as a virtual table and can return values from one column or multiple columns.
6. Suppose you need to use the most up-to-date data from a complex
query and want multiple users to be able access the information. Which
of the following solutions would be best?
a. Create a table with the complex query and allow users access to
the table.
b. Create a view with the complex query and allow users to access the
view.
c. Send users the complex query to copy and paste in their queries as
an in-line view.
87
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
A view builds the data when the view is executed and retrieves the most up-to-date information
every time that the view is run.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-62
89
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To create a view from a query result, you use a CREATE VIEW statement with the new view name
and the AS keyword, followed by the query. Adding CREATE VIEW at the beginning of the query
creates a view instead of results from the query.
a. using a one-level name for the source table in the FROM clause in
the view definition, and storing the view in a different location as
the source table
b. using a two-level name for the source table in the FROM clause in
the view definition, and storing the view in the different location as
the source table
c. embedding the LIBNAME statement with a USING clause when
creating the view
91
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Use the embedded LIBNAME statement in the USING clause to make the view definition portable. If
you use a one-level name for the source table in a view definition, the view and the source table
must reside in the same location.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-63
9. Before you run this query, which of the following changes can you make
to prevent SAS from remerging, and still produce a report?
select Order_Type,
min(Quantity) label="Min Qty"
from orion.order_fact;
93
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The SELECT list in this query specifies both a non-summarized column and a summarized column.
By default, SAS remerges unless you either group by Order_Type or remove the non-summarized
column. Specifying the NOREMERGE option prevents SAS from remerging, but then PROC SQL
does not produce a report.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-64
inventory Results
10. Which SELECT clause calculates the Product Quantity Product Pct
total percentage of inventory for Shirt 5 Shirt 50%
each product? Shoes 3 Shoes 30%
Pants 2 Pants 20%
To calculate the percentage for the Pct column, you divide each product's quantity by the sum of all
the quantities. The SELECT clause contains the non-summarized columns Product and Quantity
from the inventory table, and the summarized value of Quantity.
In the f irst pass, PROC SQL calculates the total value of Quantity. In the second pass, PROC SQL
retrieves the Product and Quantity values f or each row, and divides each value of Quantity by the
sum of all quantities f rom the f irst pass.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-65
Lesson 5
proc sql;
a b
select * ID Pet ID Pet
from a 1 Cat 1 Cat
intersect
select * 1 Dog 2 Cow
from b; 1 Pig 3 Dog
quit;
a. 1
b. 2
c. 5
d. 6
98
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The INTERSECT operator returns the unique rows that occur in both queries.
a. true
b. false
100
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Although they do not remove the duplicate rows at the same point, the EXCEPT, INTERSECT, and
UNION set operators remove duplicate rows.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-66
a. 1
b. 2
c. 5
d. 6
102
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The EXCEPT set operator selects unique rows from the first query that are not found in the second
query.
4. Adding the CORR and ALL keywords to the EXCEPT operator would
change the number of rows that this query produces.
a b
proc sql;
select * ID Pet ID Pet
from a 1 Cat 1 Cat
except
select * 1 Dog 2 Cow
from b; 1 Pig 3 Dog
quit;
a. true
b. false
104
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Because the tables have no duplicate rows and the columns are named the same, the keywords
cause no changes.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-67
a. 1
b. 2
c. 5
d. 6
106
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The OUTER UNION set operator selects all rows from both query results.
a. 2
b. 3
c. 4
d. 5
108
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The UNION set operator returns unique rows from both queries.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-68
a. 2
b. 4
c. 6
d. 8
110
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Because the columns in both tables correspond, no columns are removed. The ALL keyword
instructs PROC SQL to retain all duplicate rows in the results.
a. When used with the EXCEPT operator, the CORR keyword instructs
PROC SQL to position by same-name columns and eliminate
columns that do not have the same name in both tables from the
final results.
b. When used with the INTERSECT operator, the CORR keyword
instructs PROC SQL to overlay columns by position in the final
results.
c. When used with the OUTER UNION operator, the CORR keyword
instructs PROC SQL to eliminate columns that do not have the same
name in both tables from the final results.
112
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
When the CORR keyword is used with EXCEPT and INTERSECT, it instructs PROC SQL to align
columns that the query results have in common. The OUTER UNION CORR aligns by like column
names in both tables and includes columns that do not have the same name in both tables.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-69
114
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Not using the keyword ALL is generally less efficient because it requires PROC SQL to make an
extra pass through the data to eliminate duplicate rows.
10. PROC SQL with set operators handles columns and rows, depending on
the specific set operator and keywords used in the set operation.
a. true
b. false
116
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The INTERSECT, EXCEPT, and UNION set operators align columns by position and remove
duplicate rows by default. The OUTER UNION set operator includes all columns and rows by
default.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-70
Lesson 6
a. 9.2
b. 10:32
c. 1352050
d. Soccerballs
e. all of the above
119
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-71
121
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
When you reference a macro variable, you must precede the macro variable name with an
ampersand. You can reference macro variables anywhere in SAS code. When you reference a
macro variable within a text string, you must enclose the text string within doubl e quotation marks.
The macro processor does not resolve macro variable references that appear within single quotation
marks.
3. Which of the following options enables you to view the values of the
macro variables without using them in a report?
123
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The SYMBOLGEN system option shows you what the macro variable resolves to in the log.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-72
a. %user path=s:/workshop/data;
b. %macro path=s:/workshop/data;
c. %path=s:/workshop/data;
d. %let path=s:/workshop/data;
125
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To create a user-defined macro variable, you use the %LET statement and specify the name of the
macro variable, followed by an equal sign, and then the text string that you want to store.
5. Which of these queries places one value from the first row returned by
the SQL query into a macro variable?
a. select avg(Salary)
into :MeanSalary
from store.employee;
b. select avg(Salary)
into %MeanSalary
from store.employee;
c. select avg(Salary)
into &MeanSalary
from store.employee;
127
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The INTO clause creates one macro variable and assigns the value from the first column of the first
row of the query result. The name in the INTO clause is preceded by a colon.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-73
a. put &=MeanSalary;
b. put MeanSalary;
c. %put &=MeanSalary;
d. %put MeanSalary;
129
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
When you want to view the resolved value of a macro variable without having to include it in a
report, you can use the %PUT statement to display the resolved macro variable value along with
descriptive text in the SAS log.
7. You want to store the descriptive statistics of the Price column from the
inventory table into multiple macro variables. Which query successfully
stores mean, median, min, and max?
a. select mean(Price), median(Price), min(msrp), max(Price)
into: MeanPrice, MedianPrice, MinPrice, MaxPrice
from inventory;
131
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The INTO clause creates multiple macro variables by specifying each macro variable name with a
colon. Each macro variable is assigned the summarized value from the SELECT clause.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-74
c. select Product
into :InventoryList separated by ","
from inventory;
133
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Use the SEPARATED BY keywords to specify a character to delimit the values in the macro variable.
9. Given the table revenue below, you want to store the sum of Revenue
in a macro variable named TotalRevenue. Does the following query
store the exact value of 900000000 in TotalRevenue?
revenue
proc sql; Product Revenue
select sum(Revenue) Shirt $200,000,000
into :TotalRevenue
from revenue; Shoes $300,000,000
quit; Pants $400,000,000
a. yes
b. no
135
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The query stores the value 9E8. When storing a number, SAS uses the BEST8. format. If the
number is larger than eight digits, scientific notation is often used.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-75
10. Given the table revenue below, you want to store the sum of Revenue
in a macro variable named TotalRevenue. Which of the following
queries stores the exact value of $900,000,000 in the macro variable
TotalRevenue?
revenue
a. select sum(Revenue) format=dollar16. Product Revenue
into :TotalRevenue
from revenue; Shirt $200,000,000
Shoes $300,000,000
b. select sum(Revenue) Pants $400,000,000
into :TotalRevenue format=dollar16.
from revenue;
c. select sum(Revenue)
into :TotalRevenue
from revenue; 137
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
Use the FORMAT= column modifier in the SELECT clause to format the summarized value.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-76
Lesson 7
a. true
b. false
140
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
SAS/ACCESS technology is a family of interfaces, each licensed separately, that enables you to
read data in a third-party DBMS from within SAS. SAS/ACCESS technology for relational databases
provides an interface engine between SAS software and data in other vendors' database
management systems.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-77
2. You're familiar with the Oracle SQL implementation. You begin to use
PROC SQL but don't want to learn any of the SAS enhancements and
functions. You would like to continue to use the Oracle SQL
implementation inside SAS. Which method would you use to interact
with the Oracle database?
142
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
To accomplish your task, the best option is to use the SQL pass-through facility, which enables you
to send DBMS-specific SQL statements directly to a DBMS for execution. The syntax executes as if
you are simply coding inside the database, and processing occurs inside the database.
3. You're familiar with using PROC SQL and are connecting to an SQL
Server database. You are not familiar with the database implementation
of SQL and want to continue using PROC SQL. Which method would you
use to interact with the SQL Server database?
144
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
The SAS/ACCESS LIBNAME Engine translates your PROC SQL syntax to native DBMS SQL when
possible. This is important because SAS SQL and native database SQL can differ. So if you are
working with multiple databases, you can learn SAS SQL instead of learning native database SQL
implementations and let the engine do the work for you.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-78
a. proc fedsql;
select EmployeeID, Name, Salary, Department
from orion.employee
where = "Management";
quit;
b. proc fedsql;
select EmployeeID, Name, Salary, Department
from orion.employee
where = 'Management';
quit;
146
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
When using FEDSQL, you must use single quotation marks around a text string in the WHERE
clause. Double quotation marks are a SAS enhancement and do not run in FEDSQL.
5. You are working with an Oracle database and want to push as much of
the processing as possible into the database. Which PROC would be
better to use?
a. PROC SQL
b. PROC FEDSQL
148
C o p y r i g h t © S AS In s t i tu t e In c. Al l r i g h t s re s e r ve d .
PROC FEDSQL is a vendor-neutral ANSI SQL that pushes as much of the processing as possible
into the database.
Copyright © 2019, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.