0% found this document useful (0 votes)
25 views27 pages

Sas Quiz Attempt 2

The document outlines the details of Midterm 1 for a course on Advanced Data Management and Analysis with SAS, focusing on PROC SQL. It includes information on due date, points, questions, and attempt history, with scores from two attempts. The document also contains various SQL-related questions and answers related to data management and analysis.

Uploaded by

known8396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views27 pages

Sas Quiz Attempt 2

The document outlines the details of Midterm 1 for a course on Advanced Data Management and Analysis with SAS, focusing on PROC SQL. It includes information on due date, points, questions, and attempt history, with scores from two attempts. The document also contains various SQL-related questions and answers related to data management and analysis.

Uploaded by

known8396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.

sp25) Advanced Data Management and Analysis with SASS

Midterm 1: PROC SQL


Due Feb 28 at 11:59pm
Points 24
Questions 24
Available after Feb 24 at 8am
Time Limit 120 Minutes
Allowed Attempts 2

Attempt History
Attempt Time Score
KEPT Attempt 2 22 minutes 22.33 out of 24

LATEST Attempt 2 22 minutes 22.33 out of 24

Attempt 1 28 minutes 21.5 out of 24

 Correct answers are hidden.

Score for this attempt: 22.33 out of 24


Submitted Feb 25 at 8:25pm
This attempt took 22 minutes.

Question 1
1 / 1 pts
Which select clauses select only the uniqe combinations of age and gender?
select distinct age,distinct gender
select distinct age,gender
select unique age,gender
select distinct age gender

Question 2
1 / 1 pts
What happens if you specify a create table statement in a proc
sql step?

The query results are displayed with results grouped


by any summarized column.

[Link] 1/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

A new table is created but no query report is


displayed

The results of the query are displayed and the table


created

The new table is created but does not contain any


summarizations that were specified.

Question 3
1 / 1 pts

Which clause in the following program is incorrect?

proc sql;
select sex,age,mean(sbp) as mnsbp
from [Link] [Link]
where [Link]=[Link]
group by sex;

from
group by
select
where

[Link] 2/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Question 4
1 / 1 pts

Which of the following is true when data requested by a query


comes from joining two or more tables?

You must specify the table from which you want each
column to be read.
The tables must contain a common column

If two tables being joined contain the same column


you must specify the table from which you want the
column to be read.
The tables being joined must contain the same types of data.

Question 5
1 / 1 pts

Which clause correctly specifies that the two tables weight


and height (both in the library to which the libref tmp refers)
are to be used for the query?

select [Link],[Link]
from [Link] [Link]
from [Link],[Link]
where [Link],[Link]

[Link] 3/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Question 6
1 / 1 pts

What clause selects a subset of rows in a query?

The DISTINCT keyword


The WHERE clause
The SELECT statement
The CASE expression

IncorrectQuestion 7
0 / 1 pts

How many statements does the following program contain?


proc sql;
select sbp,dbp,sbp-dbp as pulse
from tmp.ex4
order by pulse;

One
Four
Two
Three

Question 8
1 / 1 pts

You run the following query:


proc sql;
select state,
count(*) as numhosp,
avg(beds)
from hosplist

[Link] 4/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

group by state
having avg(beds)>200;

[Link] has 22201 rows, 50 unique values of state, 150 unique values of beds, and 6
different states that have an average number of beds that is greater than 200. How many rows of
output will the query produce?
50
150
6
1

Question 9
1 / 1 pts

You wish to produce a list of all patients whose average blood pressure is greater than
130 mm/Hg.
The average blood pressure is based on (possibly) three columns, sbp1,sbp2,sbp3.
The report should list the patient’s id (stored in the column id) and the patients average
blood pressure.
Which of the following queries produces the correct list?

proc sql;
select id,avg(sbp1,sbp2,sbp3) as mnsbp,
from [Link]
where calculated mnsbp>130;

proc sql;
select id,avg(sbp1,sbp2,sbp3) as mnsbp,
from [Link]
where calculated mnsbp>130;

[Link] 5/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;
select id,avg(sbp1,sbp2,sbp3) as calculated(mnsbp)
from [Link]
where mnsbp>130;

proc sql;
select id,avg(sbp1,sbp2,sbp3) as mnsbp
from [Link]
where calculated mnsbp>130;


Question 10
1 / 1 pts

Table1

Obs id x

1 2 49

2 4 69

3 10 74

4 5 109

5 8 138

[Link] 6/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Table2

Obs id y

1 2 54

2 4 82

3 9 121

4 6 136

5 10 138

6 3 144

The data contained in the tables Table1 and Table2 is shown above. What is the result of the following
SQL program?

proc sql;
select *
from table1,table2
where [Link]=[Link];
quit;

id x id y

2 49 2 54

. . 3 144

4 69 4 82

. . 6 136

. . 9 121

10 74 10 138

[Link] 7/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

id x id y

2 49 2 54

. . 3 144

4 69 4 82

5 109 . .

. . 6 136

8 138 . .

. . 9 121

10 74 10 138

id x id y

2 49 2 54

4 69 4 82

5 109 . .

8 138 . .

10 74 10 138

id x id y

2 49 2 54

4 69 4 82

10 74 10 138

Question 11
1 / 1 pts

The files [Link] and [Link] both contain the


unique key (column) seqn. The files also contain the
columns hssex that is coded 1 for males and 2 for females
and the column hsageir that is the participants age in
years.

[Link] 8/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Which program creates a table that contains partipants


who had both an examination and lab determinations?

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]);
quit;

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=1);
quit;

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=2 and hsageir>=30);
quit;

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=2);
quit;


[Link] 9/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Question 12
1 / 1 pts

The files [Link] and [Link] both contain the


unique key (column) seqn. The files also contain the
columns hssex that is coded 1 for males and 2 for females
and the column hsageir that is the participants age in
years.
Which program creates a table that contains female
participants who are 30 or older and had both an
examination and lab determinations?

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=1);
quit;

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=2 and hsageir>=30);
quit;

[Link] 10/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]
where hssex=2);
quit;

proc sql;
create table table1 as
select * from [Link]
where seqn in (select seqn from [Link]);
quit;

Question 13
1 / 1 pts

Consider the following query:

proc sql inobs=10 number;


select Product_ID,
Unit_Cost_Price format=comma8.2,
Unit_Sales_Price format=comma8.2,
Unit_Sales_Price-Unit_Cost_Price
as Margin format=comma8.2
from orion.Price_List;
quit;
Which of the following could have been produced by this
query?

[Link] 11/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Row Product ID Unit Cost Price Unit Sales Price Margin

1 210200100009 15.50 34.70 19.20

2 210200100017 17.80 40.00 22.20

3 210200200023 8.25 19.80 11.55

4 210200600067 28.90 67.00 38.10

5 210200600085 17.85 39.40 21.55

6 210200600112 9.25 21.80 12.55

7 210200900033 6.45 14.20 7.75

8 210200900038 9.30 20.30 11.00

9 210201000050 9.00 19.60 10.60

10 210201000126 2.30 6.50 4.20

11 210201000198 26.80 60.10 33.30

1 210200100009 15.50 34.70 19.20

2 210200100017 17.80 40.00 22.20

3 210200200023 8.25 19.80 11.55

4 210200600067 28.90 67.00 38.10

5 210200600085 17.85 39.40 21.55

6 210200600112 9.25 21.80 12.55

7 210200900033 6.45 14.20 7.75

8 210200900038 9.30 20.30 11.00

[Link] 12/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Row Product ID Unit Cost Price Unit Sales Price Margin

1 210200100009 15.50 34.70 19.20

2 210200100017 17.80 40.00 22.20

3 210200200023 8.25 19.80 11.55

4 210200600067 28.90 67.00 38.10

5 210200600085 17.85 39.40 21.55

6 210200600112 9.25 21.80 12.55

7 210200900033 6.45 14.20 7.75

8 210200900038 9.30 20.30 11.00

9 210201000050 9.00 19.60 10.60

10 210201000126 2.30 6.50 4.20

Row Product ID Unit Cost Price Unit Sales Price Margin

1 210200100009 15.50 34.70 19.20

2 210200100017 17.80 40.00 22.20

3 210200200023 8.25 19.80 11.55

4 210200600067 28.90 67.00 38.10

5 210200600085 17.85 39.40 21.55

6 210200600112 9.25 21.80 12.55

7 210200900033 6.45 14.20 7.75

8 210200900038 9.30 20.30 11.00

9 210201000050 9.00 19.60 10.60


Question 14
1 / 1 pts

[Link] 13/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

The datasets (tables) table1 and table2 contain the following data:

table1

Obs id x

1 7 76

2 5 85

3 2 86

4 4 91

table2

Obs id x

1 1 123

2 2 188

3 3 169

4 4 52

5 5 159

Which of the following programs produces the output:

id

[Link] 14/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

id

proc sql;

select id from table1

except

select id from table2;

quit;

proc sql;

select id from table1

outer union

select id from table2;

quit;

proc sql;

select id from table1

intersect

select id from table2;

quit;

proc sql;

select id from table1

union

select id from table2;

quit;

[Link] 15/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Question 15
1 / 1 pts

The datasets (tables) table1 and table2 contain the following data:

table1

Obs id x

1 7 76

2 5 85

3 2 86

4 4 91

table2

Obs id x

1 1 123

2 2 188

3 3 169

4 4 52

5 5 159

Which of the following programs produces the output:

id id

7 .

5 .

2 .

[Link] 16/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

id id

4 .

. 1

. 2

. 3

. 4

. 5

proc sql;

select id from table1

except

select id from table2;

quit;

proc sql;

select id from table1

intersect

select id from table2;

quit;

proc sql;

select id from table1

union

select id from table2;

quit;

[Link] 17/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;

select id from table1

outer union

select id from table2;

quit;


Question 16
1 / 1 pts

The datasets (tables) table1 and table2 contain the following data:

table1

Obs id x

1 7 76

2 5 85

3 2 86

4 4 91

table2

Obs id x

1 1 123

2 2 188

3 3 169

4 4 52

5 5 159

[Link] 18/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Which of the following programs produces the output:

id

proc sql;

select id from table1

union

select id from table2;

quit;

proc sql;

select id from table1

outer union

select id from table2;

quit;

proc sql;

select id from table1

intersect

select id from table2;

quit;

proc sql;

select id from table1

except

select id from table2;

quit;

[Link] 19/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS


Question 17
1 / 1 pts
The table [Link] contains (among others) the columns

hsageir provides the participants age in years

hssex provides the participants' gender coded 1=male 2=female

Which program provides the number of participants who are 90 or more years old.

proc sql;

title "Program 2";

select count(*)from [Link]

where hsageir in (89,90);

quit;

proc sql;

title "Program 1";

select count(*) from [Link]

where hsageir>=90;

quit;

proc sql;

title "Program 4";

select count(*)

from [Link]

where hsageir=90 and hssex=2;

quit;

proc sql;

title "Program 3";

select count(*)from [Link]

where hsageir=90 and hssex=1;

quit;

[Link] 20/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS


Question 18
1 / 1 pts

The table [Link] contains (among others) the columns

hsageir provides the participants age in years

hssex provides the participants' gender coded 1=male 2=female

Which Program provides the number of 90 year males?

proc sql;

title "Program 2";

select count(*)from [Link]

where hsageir in (89,90);

quit;

proc sql;

title "Program 1";

select count(*) from [Link]

where hsageir>=90;

quit;

proc sql;

title "Program 4";

select count(*)

from [Link]

where hsageir=90 and hssex=2;

quit;

[Link] 21/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;

title "Program 3";

select count(*)from [Link]

where hsageir=90 and hssex=1;

quit;


Question 19
1 / 1 pts

The data set [Link] 1 contains (among others) the following columns:

lesact=self-reported leisure activity, 1=mostly inactive2=moderately active 3=highly active

male=gender,0=female 1=male

bmi=body mass index (a continuous variable)

Which program displays the average bmi for each gender among those who report being moderately active?

proc sql;

title "Program 4";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=2

group by male;

quit;

proc sql;

title "Program 2";

select lesact,mean(bmi) from nhanes1.nhanes1

where male=0 and lesact ne .

group by lesact;

quit;

[Link] 22/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;

title "Program 1";

select lesact,mean(bmi)

from nhanes1.nhanes1

where male=1 and lesact ne .

group by lesact ;

quit;

proc sql;

title "Program 3";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=1

group by male;

quit;


Question 20
1 / 1 pts

The data set [Link] 1 contains (among others) the following columns:

lesact=self-reported leisure activity, 1=mostly inactive2=moderately active 3=highly active

male=gender,0=female 1=male

bmi=body mass index (a continuous variable)

Which program displays the average bmi for each gender among those who report being mostly inactive?

proc sql;

title "Program 3";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=1

group by male;

quit;

[Link] 23/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;

title "Program 4";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=2

group by male;

quit;

proc sql;

title "Program 1";

select lesact,mean(bmi)

from nhanes1.nhanes1

where male=1 and lesact ne .

group by lesact ;

quit;

proc sql;

title "Program 2";

select lesact,mean(bmi) from nhanes1.nhanes1

where male=0 and lesact ne .

group by lesact;

quit;


Question 21
1 / 1 pts

The data set [Link] 1 contains (among others) the following columns:

lesact=self-reported leisure activity, 1=mostly inactive2=moderately active 3=highly active

male=gender,0=female 1=male

bmi=body mass index (a continuous variable)

Which program displays the average bmi for each category of lesact for females?

[Link] 24/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

proc sql;

title "Program 4";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=2

group by male;

quit;

proc sql;

title "Program 2";

select lesact,mean(bmi) from nhanes1.nhanes1

where male=0 and lesact ne .

group by lesact;

quit;

proc sql;

title "Program 3";

select male,mean(bmi) from nhanes1.nhanes1

where lesact=1

group by male;

quit;

proc sql;

title "Program 1";

select lesact,mean(bmi)

from nhanes1.nhanes1

where male=1 and lesact ne .

group by lesact ;

quit;

[Link] 25/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Question 22
1 / 1 pts
A subquery can contain a subquery
True
False

Question 23
1 / 1 pts
Which of the following creates a SQL view based on querying the table [Link]?

proc sql;
create view [Link] as
select * from [Link];
quit;

proc sql;
create [Link]
select * from [Link];
quit;

proc sql;
select * from [Link]
into view [Link];
quit;

proc sql;
insert into [Link]
select * from [Link];
quit;


PartialQuestion 24
0.33 / 1 pts
[Link] 26/27
2/25/25, 8:26 PM Midterm 1: PROC SQL: (STA5067-0001.sp25) Advanced Data Management and Analysis with SASS

Which of the following are true about sql views? (Select all that apply)

Often save space

Hide complex joins and queries from users

Prevent users from continually having to submit queries to omit unwanted rows or columns

Quiz Score: 22.33 out of 24

[Link] 27/27

You might also like