- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 718 个
- 通用积分
- 1.9496
- 学术水平
- 14 点
- 热心指数
- 19 点
- 信用等级
- 11 点
- 经验
- 7309 点
- 帖子
- 210
- 精华
- 0
- 在线时间
- 375 小时
- 注册时间
- 2011-10-26
- 最后登录
- 2020-6-28
|
用价格算,自己写一下就好了 - data input;
- length stdck $10.;
- input stdck $ price rate year;
- cards;
- 000001 452.20 1.3567 2006
- 000001 1327.26 1.9350 2007
- 000001 424.17 -0.6805 2008
- 000001 1092.70 1.5761 2009
- 000001 707.99 -0.3521 2010
- 000001 699.03 -0.0127 2011
- 000001 723.65 0.0340 2012
- 000001 893.78 0.2341 2013
- 000001 785.80 -0.1208 2014
- 000002 658.19 2.6172 2006
- 000002 1855.87 1.8115 2007
- 000002 668.01 -0.6387 2008
- 000002 1124.59 0.6837 2009
- 000002 863.30 -0.2331 2010
- 000002 794.47 -0.0791 2011
- 000002 1091.37 0.3722 2012
- 000002 879.30 -0.1887 2013
- 000002 885.87 0.0075 2014
- ;
- run;
- proc sql;
- create table out as
- select distinct a.*,
- CASE
- when a.year<2014 then exp(sum(log(b.rate+1)*(b.year-a.year<=1)))-1
- else .
- END as cum_r1,
- CASE
- when a.year<2013 then exp(sum(log(b.rate+1)*(b.year-a.year<=2)))-1
- else .
- END as cum_r2,
- CASE
- when a.year<2012 then exp(sum(log(b.rate+1)*(b.year-a.year<=3)))-1
- else .
- END as cum_r3,
- CASE
- when a.year<2011 then exp(sum(log(b.rate+1)*(b.year-a.year<=4)))-1
- else .
- END as cum_r4,
- CASE
- when a.year<2010 then exp(sum(log(b.rate+1)*(b.year-a.year<=5)))-1
- else .
- END as cum_r5
- from input a
- left join input b on a.stdck=b.stdck & a.year<b.year
- group by a.stdck,a.year
- order by a.stdck,a.year;
- quit;
复制代码
|
-
总评分: 论坛币 + 5
学术水平 + 2
热心指数 + 2
信用等级 + 2
查看全部评分
|