请选择 进入手机版 | 继续访问电脑版
楼主: 番茄奏鸣曲
1168 3

[问答] proc Sql问题 [推广有奖]

  • 0关注
  • 0粉丝

硕士生

60%

还不是VIP/贵宾

-

威望
0
论坛币
1808 个
通用积分
30.4222
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
6004 点
帖子
92
精华
0
在线时间
150 小时
注册时间
2012-2-20
最后登录
2022-4-28

15论坛币
1.JPG

2.JPG

3.JPG


好吧,我又来问问题了....
原始数据是最上面的两个,然后我已经导入数据了....
然后如果使用proc sql命令,我该怎么进行归类啊?还是要在infile进行新创建一个新的variable?
问题是这样的:
如果说,把zip42101,42103,42104设定为BG区域,剩下的邮编都是非BG区域,计算出BG 区域和非BG区域的 financial aid的总和

第二个问题:要用nested queries 把那些financial aid 高于平均数的学生

然后还有一些代码的小问题
4.JPG


上面这个代码是可以正确运行的,但是一开始我把
having 和group by 的命令上下颠倒了,然后就一直报错....然后按照上面的顺序就可以正常运行了,这个是为什么啊?
还有group by year,或者group by major为什么两个出来的结果是不一样的啊?
原理是什么啊....

谢谢谢谢谢~~~~~~~~~~·

最佳答案

yingj7093 查看完整内容

第二个,按BG分组筛选。 proc sql; select a.studentid,a.finaaid,avg(a.finaaid) as avg_finaaid,b.zip, case when b.zip in (42101,42103,42104) then "BG" else "NOTBG" end as new_zig from finaid as a left join zip as b on a.studentid=b.id group by new_zig having a.finaaid > (calculated avg_finaaid);quit;
关键词:proc sql ROC sql financial inancial having nested 平均数
yingj7093 在职认证  发表于 2017-2-19 11:30:58 |显示全部楼层 |坛友微信交流群
第二个,按BG分组筛选。
proc sql;
select a.studentid,a.finaaid,avg(a.finaaid) as avg_finaaid,b.zip,
case when b.zip in (42101,42103,42104) then "BG"
else "NOTBG" end as new_zig
from finaid as a
left join zip as b on a.studentid=b.id
group by new_zig
having a.finaaid > (calculated avg_finaaid);quit;

使用道具

proc sql;
select distinct sum(Finaaid) as Total format=dollar12.2,
case when zip in(42101,42103,42104)
then 'BG'
else 'Out BG'
end as Area
from zip p inner join finaid r
on p.id = r.studentid
group by area
order by Total;


我自己解决了~~~~~~~~~~~~~·

使用道具

yingj7093 在职认证  发表于 2017-2-24 15:56:26 |显示全部楼层 |坛友微信交流群
第一个问题。
proc sql;
select a.studentid,a.finaaid,sum(a.finaaid) as sum_finaaid,b.zip,
case when b.zip in (42101,42103,42104) then "BG"
else "NOTBG" end as new_zig
from finaid as a
left join zip as b on a.studentid=b.id
group by new_zig;quit;

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 12:53