7: Using SQL in SAS Flashcards

1
Q
What is the correct order of the following four clauses?
	 a.  from ...
     select ...
      where ...
       order by ...
 b.  order by ...
 from ...
  select ...
   where ...

 c.  select ...
 where ...
  order by ...
   from ...

 d.  select ...
 from ...
  where ...
   order by ...
A

D

First is SELECT, second is FROM, third is WHERE, and fourth is ORDER BY.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following is false regarding the SQL procedure?

 a. Column names are separated with commas.
 b. The procedure ends with a QUIT statement.
 c. Formats can be specified in the FROM clause.
 d. The SELECT and FROM clauses are required in the SELECT statement.
A

C

Formats are specified in the SELECT clause after the column name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which syntax is valid for creating a computed column in the SELECT clause?

 a. Ratio = Height/Weight
 b. Ratio as Height/Weight
 c. Height/Weight = Ratio
 d. Height/Weight as Ratio
A

D

Computed columns are created by specifying the expression, the keyword AS, and the column name, in that order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The SELECT statement creates a report. Which clause can be added before the SELECT clause to create a table?

 a. create work.new =
 b. create work.new table
 c. create table work.new as
 d. create table=work.new as
A

C

To create a table, add the CREATE TABLE NEW-TABLE-NAME AS clause before the SELECT clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Which SELECT statement produces the given output?
Name	Height
Thomas	57.5
Joyce	51.3
	 a.  select Name Height
      from sashelp.class
      where age=12
      order by Height;
	 b.  select Name, Height
      from sashelp.class
      where age=12
      order by Height desc;
	 c.  select Name Height
      from sashelp.class
      where age=12
      order by desc Height;
	 d.  select Name, Height
      from sashelp.class
      where age=12
      order by desc Height;
A

B
In the SELECT clause, column names are separated with commas. In the ORDER BY clause, DESC goes after the column name. ASC is the default sort order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which SQL statement can delete tables?

 a. DROP
 b. VOID
 c. DELETE
 d. SELECT
A

A

The DROP TABLE statement deletes tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
f an inner join is performed on the following tables based on the ID and IDNO columns, how many rows will be in the PROC SQL report?
Name	ID
Jack	111
Mary	333
Jane	555
IDNO	Salary
111           75000
222        83000
333        82000
 a. one
 b. two
 c. three
 d. four
A

B

An inner join gives matches only. Jack (111) and Mary (222) are the matches in this example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which statement has the correct syntax for performing an inner join?
a. select ID, Name, Salary
from one join two
on ID=IDNO;

 b.  select ID, Name, Salary
   from one join two
   where ID=IDNO;

 c.  select ID, Name, Salary
   from one inner join two
   on ID=IDNO;

 d.  select ID, Name, Salary
   from one inner join two
   where ID=IDNO;
A

C
To perform an inner join, specify INNER JOIN between two table names and specify the matching condition in an ON clause (not a WHERE clause).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which ON clause has valid qualifying syntax?
a. from empsau inner join phonec
on e.empid=p.empid;

 b.  from empsau inner join phonec
   on left.empid=right.empid;

 c.  from empsau inner join phonec
   on first.empid=second.empid;

 d.  from empsau inner join phonec
   on empsau.empid=phonec.empid;
A

D
To qualify a column, put the table name and a period before the column name. Qualifying is needed when a column is in multiple tables. The name empsau.empid refers to the empid column in the empsau table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which FROM clause properly creates aliases?

 a. from empsau=e inner join phonec=p
 b. from empsau(e) inner join phonec(p)
 c. from empsau as e inner join phonec as p
 d. from empsau of e inner join phonec of p
A

C
To create an alias in the FROM clause, put the word AS and the alias after the table name. The word AS is optional. The alias can be used when qualifying a column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly