BookmarkSubscribeRSS Feed
ttp
Fluorite | Level 6 ttp
Fluorite | Level 6

data work.one;
input name$ years;
cards;
Joyce 9
John 4
John 2
jane 6
Tomas 8
;
data work.two;
input name$ years;
cards;
Joyce 31
John 42
Robert 25
Bob 22
Jeff 42
;
proc sql;
select Avg(years)
label="Average of Employment"
from work.one
where name in
(select *
from work.one
except corr
select *
from work.two);
quit;

what will be the output?

A. Average of Employment 5

B.Average of Employment 7

C Average of Employment 6

D. ERROR: Subquery evaluated to more than one row

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

A subquery cannot select more than one column.

D.

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
D says rows but the issue is columns.
D for the error.
bobpep212
Quartz | Level 8

Yeah - what they said. Start at the inner subquery. You are sort of creating a two column table right there. The where statement is looking for name from a list of names, but you haven't specified which of those two columns has name. Even if the select * from subquery has a column called name, it isn't going to assume it contains the same "name" data that's in your outer query.

 

Good luck on the exam. I'm studying for it too.  

ttp
Fluorite | Level 6 ttp
Fluorite | Level 6

yes very well explained. 

If this question is given what Option do  you choose.

D or B.

My guess is D the closest I can think of. 

yes I am preparing for the exam as well. Good luck to you as well.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

as @bobpep212 says change the second * to name and the answer is 7 for B but the code Errors. as is.

 

data work.one;
input name$ years;
cards;
Joyce 9
John 4
John 2
jane 6
Tomas 8
;
data work.two;
input name$ years;
cards;
Joyce 31
John 42
Robert 25
Bob 22
Jeff 42
;
proc sql;
select Avg(years)
label="Average of Employment"
from work.one
where name in
(select *
from work.one
except corr
select name from work.two);
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1701 views
  • 0 likes
  • 3 in conversation