使用proc sql获取列的第一行

问题描述 投票:0回答:1

给出下面的脚本, 对于每支球队,至少有 30 次助攻的球员的最高收入者;

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;

这里的主要问题是first()函数返回字符串中的第一个字符而不是第一行。

除 proc sql 之外的任何解决方案也将受到欢迎

sas proc-sql
1个回答
0
投票

如果我理解得很好,你应该这样写你的查询:

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;

这样你就可以按球队分组,然后选择由

max(salary)
提供的薪水最高且至少有30次助攻的球队。请给我一个反馈,表明该查询按您的预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.