楼主: firefox29
4953 4

关于PROC SQL利用子查询的问题 [推广有奖]

  • 11关注
  • 1粉丝

博士生

28%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0.2251
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
3694 点
帖子
131
精华
0
在线时间
305 小时
注册时间
2012-1-23
最后登录
2023-6-20

楼主
firefox29 发表于 2014-2-20 16:01:35 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
我的设想是按不同的分组变量求和,最后把新的求和变量和原数据放到一个表里;括号里面是两个子查询计算变量,第一次用了begindate作分组变量求和,第二次用了begindate,prodtype作分组变量求和;

但是结果总是出现“error: 子查询不止一行”;
程序如下:

proc sql;
create table test01 as
select begindate,prodtype,principal,


(select begindate,sum(principal) as sumpp2
from task01_raw
group by begindate),

(select begindate,prodtype,
sum(principal) as sumpp1
from task01_raw
group by begindate,prodtype)

from task01_raw;
quit;

求教如何实现



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:proc sql sql ROC 子查询 PRINCIPAL

沙发
linusx 发表于 2014-2-21 10:34:58
the subquery must return a single, unambiguous result for each value

藤椅
firefox29 发表于 2014-2-21 11:06:56
linusx 发表于 2014-2-21 10:34
the subquery must return a single, unambiguous result for each value
I don't see your point. The subquery can be excuted by its own sql proc.
Furthermore the code followed is valid:

proc sql;
create table test01 as
select begindate,prodtype,principal,
sum(principal) as sumpp2
from task01_raw
group by begindate;
quit;

Only I want to know how to merge several procedure like this.

板凳
yongyitian 发表于 2014-2-21 12:22:24
  1. /* try this */

  2. proc sql;
  3.     create table test01 as
  4.     select a.begindate,
  5.            a.prodtype,
  6.            a.sumpp1,
  7.            sum(a.principal) as sumpp2
  8.      from (select begindate, prodtype, principal, sum(principal) as sumpp1
  9.            from task01_raw
  10.            group by begindate, prodtype
  11.            ) as a
  12.     group by a.begindate;
  13. quit;
复制代码
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
lunix的昵称 + 1 + 1 精彩帖子
firefox29 + 1 + 1 + 1 观点有启发

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 1   查看全部评分

报纸
firefox29 发表于 2014-2-21 13:43:05
yongyitian 发表于 2014-2-21 12:22
很有启发``3Q

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 05:51