楼主: dabao1988
1498 7

求教!有点复杂的最大值问题 [推广有奖]

  • 2关注
  • 1粉丝

硕士生

58%

还不是VIP/贵宾

-

威望
0
论坛币
431 个
通用积分
0.0364
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1555 点
帖子
58
精华
0
在线时间
274 小时
注册时间
2010-12-31
最后登录
2020-9-29

楼主
dabao1988 发表于 2012-11-21 13:58:11 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
各位好。sas是新手,不知道下面这个问题怎么解决。还请大家帮忙。

我的数据是这样子的。
stock_codedayprice

1

20111231

1

1

20111230

2

1

20111229

3

1

20111228

4

.......

数据一直到1995年。
我想看,对于每一天来说,之前的一年,的price的最大值。比如,2011年12月31号,我想把,一直到2011年1月1日,最大值挑出来。 2011年12月30号,我想把,一直到2010年12月30日,这期间的最大值挑出来。

sas新手,真的不知道该怎么弄。。。。谢谢!

二维码

扫码加我 拉你入群

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

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

关键词:最大值 Price coded Stock Rice 最大值 price

沙发
老师她摸我 发表于 2012-11-21 15:45:15
proc sql;
select max(price),year(day) as year from yourdsn
group by year;
quit;
欢迎加入SAS群:144839730-蜗牛

藤椅
jessie1917 发表于 2013-8-20 17:05:16
楼主我爱你!

板凳
beijingdizheng 发表于 2013-8-20 18:53:21
可以把price的值赋给一个数组
用数组来解决

报纸
邓贵大 发表于 2013-8-20 22:35:02
define an ordered hash object by descending price and date
已有 1 人评分学术水平 信用等级 收起 理由
jingju11 + 3 + 1 观点有启发

总评分: 学术水平 + 3  信用等级 + 1   查看全部评分

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

地板
yuerqieqie 发表于 2013-8-21 21:06:20
如果所有的计算都是针对同一支股票,365天包括当天的话,
data result;
        if _N_= 1 then do;
                declare hash h(dataset: "input", multidata: 'y');
                h.defineKey('stock_code');
                h.defineData('day', 'price');
                call missing(day, price);
                h.defineDone();
        end;

        set input(rename = (day = current_day price = current_price));
        max_price = 0;

        /* Iterate over the hash */
        rc = h.find(key: stock_code);
        do while (rc = 0);
                if (current_day - 365 < day <= current_day) then do;
                        max_price = max(max_price, price);
                end;
                rc = h.find_next(key: stock_code);
        end;
        keep stock_code current_day current_price max_price;
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
jingju11 + 5 + 5 + 5 Barely seen a good code for HASH. but th

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

7
jingju11 发表于 2013-8-23 06:42:07
yuerqieqie 发表于 2013-8-21 21:06
如果所有的计算都是针对同一支股票,365天包括当天的话,
data result;
        if _N_= 1 then do;
I have barely seen a good code on properly using HASH object in a necessary situation; this is clearly the one. I try to program in data step, it turns out a ton of lines of coding...
Jingju

8
邓贵大 发表于 2013-8-25 23:26:46
DELETE
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

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

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