楼主: psps1984
5432 8

[问答] SAS 时间序列 如何抽取固定时间点数据 [推广有奖]

  • 0关注
  • 1粉丝

已卖:12份资源

副教授

2%

还不是VIP/贵宾

-

威望
0
论坛币
171 个
通用积分
154.3808
学术水平
8 点
热心指数
7 点
信用等级
9 点
经验
3713 点
帖子
216
精华
0
在线时间
1153 小时
注册时间
2005-11-22
最后登录
2025-10-13

楼主
psps1984 发表于 2014-6-5 12:03:23 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
各位高手,有个SAS问题求助:

#RICDate[G]Time[G]Price
AUD=D3

1-Jan-13

16:46:52.242

1.013

AUD=D3

1-Jan-13

16:47:36.488

1.013

AUD=D3

1-Jan-13

17:18:48.993

1.014

AUD=D3

1-Jan-13

17:19:36.308

.

AUD=D3

1-Jan-13

17:24:09.758

1.014

AUD=D3

1-Jan-13

17:24:10.300

1.013

AUD=D3

1-Jan-13

17:24:19.303

1.013

AUD=D3

1-Jan-13

17:24:22.764

.

AUD=D3

1-Jan-13

17:24:38.749

1.015

AUD=D3

1-Jan-13

17:24:39.249

1.015



数据格式如上。
想抽取每天下午四点钟(16:00:00.000)的数据,
如果该时点没有数据,则计算出4点钟之前和之后数值的加权平均(权重为该数据时间与4点钟间隔的倒数)。
不知SAS如何实现?
多谢!

二维码

扫码加我 拉你入群

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

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

关键词:时间序列 SAS问题 Price ICEA Rice 如何

沙发
lixiang101 发表于 2014-6-5 12:16:38
看不懂!太专业了!

藤椅
bbear 发表于 2014-6-6 07:51:17
给个方向, 你自己试看看

step 1:
PTime=Time- 16:00 ; positive 4:00 之后
if Ptime>=0 then do
  Ntime=10000000;
end;
else do ; *NTime=16:00 -time ; negative 4:00 之前
  Ptime=10000000;
  Ntime=abs(PTime);
end;

step 2:
-> 取出 Ptime 最小值, Ntime最小值.
#每个RIC 最多只有2笔, (要用distinct, nodup 处理过, 才会剩2笔)
#可能还要remove 掉, 离太久的, 如9:00

step 3:
  1. 如果​​ Ptime 有等于(接近)0
    outp=price;
  2. else 如果 有一笔,
    outp=price;
  3. else 如果 有二笔,
    outp=(priceA * NTIME +price B * PTIME)/(PTime+NTIME);

#也许step 3 还可以化简,有简单的写法.

想像
STEP 1 可以用 DATA 做.
STEP 2 可以用 SQL, or DATA 做.
STep 3 可以用 SQL 做.

板凳
yongyitian 发表于 2014-6-6 11:47:42
  1. data test;
  2. format date yymmdd10. ;
  3. format time time8.;
  4.    date = '01jan2013'd;
  5.       do time = '15:45:00't to '16:15:00't by 60;
  6.         output;
  7.       end;
  8.   date = '02jan2013'd;
  9.       do time = '15:45:00't to '16:15:00't by 60;
  10.         if time ^='16:00:00't then output;
  11.       end;
  12. run;

  13. data want;
  14.   set test;
  15.     time_lag = lag(time);
  16.         if time = '16:00:00't then output;
  17.     else if time - '16:00:00't > 0  and  time_lag - '16:00:00't < 0 then do;
  18.        time = (time+time_lag) / (time -'16:00:00't)*30;  
  19.        /* change the calculation as you want */
  20.        output;
  21.      end;
  22.    drop time_lag;
  23. run;
复制代码

报纸
psps1984 发表于 2014-6-6 13:45:59
yongyitian 发表于 2014-6-6 11:47
多谢您的回复!
我的数据总共一年(1-Jan-2013 to 31-Dec-2013),想找出每一天的这个时间点的数据price.
怎么扩展?

地板
psps1984 发表于 2014-6-6 15:18:47
另外想问下 如何在原来的数据中插入每天的一个固定时间点(16:00:00.000)
用merge?

7
yongyitian 发表于 2014-6-6 20:35:14
  1. /* 先按日期,时间排序。然后, 16点缺失时,插入16点数据。 

  2. 你可以对price做任何想要的计算.  */

  3. proc sort data=test;
  4.     by date time;
  5. run;
  6. data want;
  7.   set test;
  8.     time_lag = lag(time);
  9.     price_lag = lag(price);
  10. output;
  11.     if time - '16:00:00't > 0  and  time_lag - '16:00:00't < 0 then do;
  12.        time = '16:00:00't;  
  13.        /* add calculations on price at here */
  14.        /* for example: price = (price + price_lag)/2; */
  15.        output;
  16.      end;
  17.    drop time_lag price_lag;
  18. run;
  19. proc sort data=want; by date time; run;
复制代码

8
psps1984 发表于 2014-6-8 15:56:00
多谢您的代码。
继续提问:现在需要提取每半点的price (如12:30,1:00,1:30 etc.)如果半点时没有数据,则用差值法补齐。
Prices at 30-minute intervals are constructed from the interpolation of the mid-quotes immediately before and after the 30-minute mark.
这个如何SAS实现? 多谢!

9
yongyitian 发表于 2014-6-9 10:46:33
先用 proc timeseries; 填充 missing value。
可以参考这个例子.
http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_timeseries_sect036.htm


/* 输出每整点和半点的数据 */
data want;
    set data_without_missing;
    if mod(time, 1800) = 0 then output;
run;

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-20 12:35