楼主: caibirdcnb
7145 7

[原创博文] 请问高手SAS的PROC SQL语句如何实现逐行累加?谢谢! [推广有奖]

  • 0关注
  • 37粉丝

讲师

47%

还不是VIP/贵宾

-

威望
0
论坛币
1367 个
通用积分
16.5538
学术水平
67 点
热心指数
70 点
信用等级
64 点
经验
6762 点
帖子
206
精华
2
在线时间
433 小时
注册时间
2011-8-31
最后登录
2023-9-23

楼主
caibirdcnb 发表于 2011-10-28 16:24:11 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
例如:
A B
1 1
2 3
3 6
4 10
...

在上面的例子中,希望由A产生B。
在SAS语句中,可以通过B + A实现。
但如果使用PROC SQL语句呢?(我搜索百度发现其它SQL有over语句,但SAS中好像没有。)

请高手指教,非常感谢!
二维码

扫码加我 拉你入群

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

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

关键词:proc sql sql语句 如何实现 sas的 ROC 搜索百度 如何

沙发
可~乐 发表于 2011-10-28 16:36:08
用retain就可以做了

藤椅
oloolo 发表于 2011-10-28 18:46:52
data a;
   input a;
cards;
1
2
3
4
;
run;

proc sql;
       create table b as
       select a.a, sum(b.a) as b
       from   a as a, a as b
       where  a.a>=b.a
       group by a.a
       ;
quit;
已有 1 人评分学术水平 收起 理由
jingju11 + 2 观点有启发

总评分: 学术水平 + 2   查看全部评分

板凳
denver 发表于 2011-10-28 20:13:27
oloolo 发表于 2011-10-28 18:46
data a;
   input a;
cards;
this is not a general solution. what if the series not sorted ascendingly?
Denver大家一起读Paper系列索引贴:
https://bbs.pinggu.org/thread-1430892-1-1.html

报纸
jingju11 发表于 2011-10-28 22:13:17
oloolo 发表于 2011-10-28 18:46
data a;
   input a;
cards;
模仿以下,既然位置更重要(but my code looks very stupid because of the funny sql function)。
京剧

  1. data a;
  2.     input x@@;
  3. cards;
  4. 1 3 2 7 4 -1 2 0 4
  5. ;
  6. proc sql;
  7.    create table b(drop =n) as
  8.     select distinct a1.n, a1.x, sum(a2.x) as b
  9.         from   
  10.           (select monotonic() as n, * from  a ) as a1
  11.             inner join
  12.           (select monotonic() as n, * from  a ) as a2
  13.             on  a1.n ge a2.n
  14.         group by a1.n
  15. ;
  16. quit;
复制代码

地板
bobguy 发表于 2011-10-29 11:03:27
oloolo 发表于 2011-10-28 18:46
data a;
   input a;
cards;
SQL will be a clumsy approach for solving this problem. There is no observation order concept in database or SQL language. For example, find the third largest value of a variable.  

The proposed solution would be wrong in following data ordering,

data a;
   input a;
cards;
1
6
3
4
;
run;

data b;
   set a;
   b+a;
run;

proc print;run;

proc sql;
      
       select a.a, sum(b.a) as b
       from   a as a, a as b
       where  a.a>=b.a
       group by a.a
       ;
quit;

7
oloolo 发表于 2011-10-29 22:55:07
bobguy 发表于 2011-10-29 11:03
SQL will be a clumsy approach for solving this problem. There is no observation order concept in d ...
那就用jingju11的代码

8
caibirdcnb 发表于 2011-10-31 10:27:11
thank you very much for all of you's help, I learn a lot.

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 22:45