作者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/m.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