楼主: jjtww
8592 13

[有偿编程] 5分钟间隔的高频数据预处理 [推广有奖]

  • 10关注
  • 5粉丝

已卖:673份资源

博士生

1%

还不是VIP/贵宾

-

威望
0
论坛币
13076 个
通用积分
2.3774
学术水平
2 点
热心指数
5 点
信用等级
2 点
经验
2841 点
帖子
189
精华
0
在线时间
194 小时
注册时间
2010-6-7
最后登录
2016-4-1

楼主
jjtww 发表于 2013-5-13 12:05:07 |AI写论文
50论坛币
现有5分钟间隔的高频数据 douyou.txt (1.86 MB)
格式是CSV的,用下面的代码可以转成SAS数据。
  1. data WORK.DOUYOU    ;
  2.              %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
  3.             infile 'C:\Users\Akward\Desktop\SAIF\douyou.txt' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
  4.                 informat 日期 yymmdd10. ;
  5.                 informat 时刻 time20. ;
  6.                 informat 开盘价 best32. ;
  7.                 informat 最高价 best32. ;
  8.                 informat 最低价 best32. ;
  9.                 informat 收盘价 best32. ;
  10.                 format 日期 yymmdd10. ;
  11.                 format 时刻 hhmm5. ;
  12.                 format 开盘价 best12. ;
  13.                 format 最高价 best12. ;
  14.                 format 最低价 best12. ;
  15.                 format 收盘价 best12. ;
  16.              input
  17.                          日期
  18.                          时刻
  19.                          开盘价
  20.                          最高价
  21.                          最低价
  22.                          收盘价
  23.              ;
  24.              if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
  25. run;
复制代码
每一天数据完整的时刻为:
9:01
9:06
9:11
9:16
9:21
9:26
9:31
9:36
9:41
9:46
9:51
9:56
10:01
10:06
10:11
10:31
10:36
10:41
10:46
10:51
10:56
11:01
11:06
11:11
11:16
11:21
11:26
13:31
13:36
13:41
13:46
13:51
13:56
14:01
14:06
14:11
14:16
14:21
14:26
14:31
14:36
14:41
14:46
14:51
14:56

这45个时刻。
要求:
  用SAS设计一个程序,检查每一天是否都有这45个时刻,若没有45条数据,用前一个时刻的值补上这个时刻的数据。因数据量较大,需要程序运行效率高些。烦请大牛帮忙!在此感谢下。

最佳答案

playmore 查看完整内容

首先你做一张完整时间间隔的表,然后左连接行情表 这样可以得到完整的表,只不过若某时间点没有行情数据,则该行的行业变量为空 然后用我的宏FillMissWithNonMiss填补下缺失值就好了
关键词:数据预处理 高频数据 预处理 detection delimiter 高频 间隔

回帖推荐

zhou.wen 发表于4楼  查看完整内容

By the way,the code you use to import the stock data might by wrong. The variable name can not be chinese character. I change it as follow:

zhou.wen 发表于3楼  查看完整内容

using the hash component will be more efficient!
已有 1 人评分经验 收起 理由
crackman + 100 鼓励积极发帖讨论

总评分: 经验 + 100   查看全部评分

本帖被以下文库推荐

沙发
playmore 发表于 2013-5-13 12:05:08
首先你做一张完整时间间隔的表,然后左连接行情表
这样可以得到完整的表,只不过若某时间点没有行情数据,则该行的行业变量为空
然后用我的宏FillMissWithNonMiss填补下缺失值就好了
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

藤椅
zhou.wen 发表于 2013-5-13 19:19:32
using the hash component will be more efficient!
  1. data work.time;
  2. input time time5. ;
  3. format time time5.;
  4. cards;
  5. 9:01
  6. 9:06
  7. 9:11
  8. 9:16
  9. 9:21
  10. 9:26
  11. 9:31
  12. 9:36
  13. 9:41
  14. 9:46
  15. 9:51
  16. 9:56
  17. 10:01
  18. 10:06
  19. 10:11
  20. 10:31
  21. 10:36
  22. 10:41
  23. 10:46
  24. 10:51
  25. 10:56
  26. 11:01
  27. 11:06
  28. 11:11
  29. 11:16
  30. 11:21
  31. 11:26
  32. 13:31
  33. 13:36
  34. 13:41
  35. 13:46
  36. 13:51
  37. 13:56
  38. 14:01
  39. 14:06
  40. 14:11
  41. 14:16
  42. 14:21
  43. 14:26
  44. 14:31
  45. 14:36
  46. 14:41
  47. 14:46
  48. 14:51
  49. 14:56
  50. run;

  51. data time;
  52. set time;
  53. id=_n_;
  54. rename time=time1;
  55. run;
  56. data test;
  57. set douyou;
  58. if _n_>3 and  _n_<20 then delete;
  59. run;
  60. data work.all;
  61. if (_n_=1) then do;
  62. declare hash myhash(dataset:"work.Time");
  63. myhash.definekey("Id");
  64. myhash.definedata("time1");
  65. myhash.definedone();
  66. call missing(id,Time1);
  67. end;
  68. set work.test;
  69. retain barid temp;
  70. by date;
  71. if first.date then barid=1;
  72. myhash.find(key:barid);
  73. /*if time>time1 then do;*/
  74. temp=time;
  75. do while(temp^=time1 );
  76.         time=time1;
  77.         barid+1;
  78.         myhash.find(key:barid);
  79.         if temp<time1 then do;
  80.     barid+(-1);
  81.         myhash.find(key:barid);
  82.         temp=time1;        
  83.         end;
  84.         else do;
  85.                 tag=0;
  86.                 output;               
  87.         end;
  88. end;
  89. time=time1;
  90. tag=1;
  91. output;
  92. barid+1;
  93. run;

  94. data out;
  95. set all;
  96. retain refo refh refl refc;
  97. if tag=1 then do;
  98. refo=o;
  99. refh=h;
  100. refl=l;
  101. refc=c;
  102. end;
  103. if tag=0 then do;
  104. o=refo;
  105. h=refh;
  106. l=refl;
  107. c=refc;
  108. end;
  109. keep date time o h l c;
  110. run;
复制代码
已有 1 人评分经验 收起 理由
crackman + 100 鼓励积极发帖讨论

总评分: 经验 + 100   查看全部评分

Practice Is The Best Teacher!

板凳
zhou.wen 发表于 2013-5-13 19:25:54
By the way,the code you use to import the stock data might by wrong.
The variable name can not be chinese character.
I change it as follow:
  1. data WORK.DOUYOU    ;
  2.              %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
  3.             infile 'C:\Users\Administrator\Desktop\douyou.txt' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
  4.                 informat Date yymmdd10. ;
  5.                 informat Time time20. ;
  6.                 informat O best32. ;
  7.                 informat H best32. ;
  8.                 informat L best32. ;
  9.                 informat C best32. ;
  10.                 format Date yymmdd10. ;
  11.                 format Time hhmm5. ;
  12.                 format O best12. ;
  13.                 format H best12. ;
  14.                 format L best12. ;
  15.                 format C best12. ;
  16.              input
  17.                          Date
  18.                          Time
  19.                          O
  20.                          H
  21.                          L
  22.                          C
  23.              ;
  24.              if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
  25. run;
复制代码
已有 1 人评分经验 收起 理由
crackman + 100 鼓励积极发帖讨论

总评分: 经验 + 100   查看全部评分

Practice Is The Best Teacher!

报纸
boe 发表于 2013-5-13 19:30:01
zhou.wen 发表于 2013-5-13 19:19
using the hash component will be more efficient!
强悍!学习了。
Gorgeous girl , I love !

地板
zkymath 在职认证  发表于 2013-5-14 15:15:21
不懂!学习了

7
jjtww 发表于 2013-5-14 20:31:11
申请版主加精!

8
jjtww 发表于 2013-5-15 13:28:57
zhou.wen 发表于 2013-5-13 19:19
using the hash component will be more efficient!
这个没看懂啊?能解释下吗?就是do while 循环里的不明白

9
jjtww 发表于 2013-5-15 13:29:01
zhou.wen 发表于 2013-5-13 19:19
using the hash component will be more efficient!
这个没看懂啊?能解释下吗?就是do while 循环里的不明白

10
zhou.wen 发表于 2013-5-15 13:48:31
jjtww 发表于 2013-5-15 13:29
这个没看懂啊?能解释下吗?就是do while 循环里的不明白
You can use the Data Step Debugger to figure out the logic detail in the data step by modify the code as follows.
  1. data work.all/debug;
复制代码
you can type the commands at the command line,such as 'step' to execute the statement and move to next line. the code 'examine _all_' to list all the variable and their values in in the DEBUGGER LOG window.
  1. step
  2. examine _all_
复制代码





Practice Is The Best Teacher!

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

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