作者blackhores (八亿)
看板Statistics
标题[程式] SAS 资料分组运算
时间Fri Feb 17 18:31:30 2017
[软体程式类别]:
SAS
[程式问题]:
资料处理
[软体熟悉度]:
新手
[问题叙述]:
大家好,初接触SAS帮忙整理资料,遇到以下困难,恳求高手帮解决
以下依照目前所理解的逻辑假设资料:
SYMBOL NUM C/P DELTA DATE A B C D
AAA 1000 C 0.1 1/1 10 20 0 0
AAA 1000 C 0.2 1/1 5 10 5 0
AAA 1000 C 0.5 1/1 5 0 5 5
AAA 1000 C 0.1 1/2 5 5 5 0
AAA 1000 C 0.3 1/3 0 5 10 5
BBB 500 C 0.1 1/3 20 10 10 10
BBB 500 P 0.2 1/4 5 0 5 5
BBB 500 P 0.3 1/4 10 0 5 5
希望利用SAS整理,求得目标:
SYMBOL,A/B/C/D,C/P,DATE = *DELTA /NUM
AAA,A,C,1/1 = (10*0.1+5*0.2+5*0.5)/1000
AAA,B,C,1/1 = (20*0.1+10*0.2+0*0.5)/1000
AAA,A,C,1/2 = (5*0.1)/1000
...
希望求得A,B,C,D 在相同或不同SYMBOL,DATE,C/P,下所计算出的值,
如果SYMBOL,DATE,C/P皆相同,就要各自*DELTA後相加,
因为初接触不久,不知从何着手,
只想到按SYMBOL排序後再依DATE跟C/P分组再分组後再计算,
文长,感谢您耐心看完,如果我叙述的不是很清楚,还请直接发问,谢谢!
[程式范例]:
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.240.185.52
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1487327496.A.AFE.html
1F:推 anniecs: proc sql; create table new as 02/17 23:15
2F:→ anniecs: select SYMBOL,'A' as ABCD, CP, date,sum(A*delta/num) 02/17 23:16
3F:→ anniecs: from old group by SYMBOL, ABCD, CP, date 02/17 23:16
4F:→ anniecs: union 02/17 23:17
5F:→ anniecs: select SYMBOL,'B' as ABCD, CP, date, sum(B*delta/num) 02/17 23:17
6F:→ anniecs: from test group by SYMBOL, ABCD, CP, date 02/17 23:17
7F:→ anniecs: union 02/17 23:18
8F:→ anniecs: select SYMBOL,'C' as ABCD, CP, date, sum(C*delta/num) 02/17 23:18
9F:→ anniecs: from old group by SYMBOL, ABCD, CP, date 02/17 23:19
10F:→ anniecs: union 02/17 23:19
11F:→ anniecs: select SYMBOL,'D' as ABCD, CP, date, sum(D*delta/num) 02/17 23:19
12F:→ anniecs: from old group by SYMBOL, ABCD, CP, date; quit; 02/17 23:20
13F:→ blackhores: 真的非常谢谢您抽空解答!明天会好好来研究!谢谢 02/18 00:31
14F:→ blackhores: 想再请教 'A' as ABCD 涵义是什麽,A、B、C、D分属不 02/19 15:30
15F:→ blackhores: 同栏位不用加","吗?? 谢谢 02/19 15:30