Obtain the first row of a column with proc sql

58 Views Asked by At

Given a script below, for each team, the top earner for players that have at least 30 assists;

proc sql;
create table basketball_summary as 
select team, salary, first(case when nAssts >= 30 then Name end) as Name
from sashelp.baseball
group by team
order by team, salary;
quit;

the main issue issue here is that the first() function returns the first character in a string instead of the first row.

Any solution other than proc sql would also be welcome

1

There are 1 best solutions below

0
nagytoth1 On

If I understand it well, you should write your query like this:

proc sql;
create table basketball_summary as 
select team, Name, salary
from sashelp.baseball
where nAssts >= 30
group by team
having salary = max(salary)
order by team;
quit;

This way you group by team, and select the one that has the best salary, provided by max(salary), and has at least 30 assists. Please, give me a feedback that the query works as you expect.