楼主: jungsee
1549 6

公司+年 结构数据 重新编排 与编号 [推广有奖]

  • 0关注
  • 10粉丝

已卖:857份资源

讲师

31%

还不是VIP/贵宾

-

威望
0
论坛币
2094 个
通用积分
76.6887
学术水平
12 点
热心指数
15 点
信用等级
8 点
经验
75593 点
帖子
255
精华
0
在线时间
637 小时
注册时间
2004-12-20
最后登录
2025-10-16

楼主
jungsee 发表于 2015-2-5 21:02:43 |AI写论文
100论坛币
我的数据结构是这样的:

QQ图片20150205205924.png (5.95 KB)

计算结果

计算结果

export1.zip
下载链接: https://bbs.pinggu.org/a-1728721.html

259 Bytes

CSV文件

本附件包括:

  • export1.csv

关键词:数据结构 编号 SAS

沙发
mingfeng07 学生认证  发表于 2015-2-5 21:02:44
  1. data b;
  2. set a;
  3. by firm year;
  4. if first.firm then sum=0;
  5. if export=0 then sum+1;
  6. if sum=0 then delete;
  7. run;
  8. data c;
  9. set b(drop=sum);
  10. by firm year;
  11. if first.firm then sum=0;
  12. if export^=0 then sum+1;
  13. if sum=0 then delete;
  14. run;
  15. data d;
  16. set c(drop=sum);
  17. by firm year;
  18. array aa{4} export1-export4;
  19. export1=lag(export);
  20. export2=lag2(export);
  21. export3=lag3(export);
  22. export4=lag4(export);
  23. do i=1 to 4;
  24. if aa(i)=. then aa(i)=0;
  25. if i>t then aa(i)=0;
  26. end;
  27. if first.firm then do; t=1;
  28.   exit=0;export1=0;export2=0;export3=0;export4=0;
  29. end;
  30. else t+1;
  31. if export1*export2^=0 and export=0 then exit=1;
  32. else if export=0 and export1=0 and export2=0 and export3^=0 and export4=0 then exit=1;
  33. else exit=0;
  34. if export2*export3^=0 and export=0 then delete;
  35. if export3*export4^=0 and export=0 then delete;
  36. if export=0 and export1=0 and export2=0 and export3=0 then delete;
  37. run;
  38. data e;
  39. set d(keep=firm year export exit);
  40. by firm year;
  41. exit1=lag(exit);
  42. if first.firm then group_in_firm=1;
  43. if exit1-exit=1 then group_in_firm+1;
  44. run;
  45. data f;
  46. set e(drop=exit1);
  47. by firm group_in_firm;
  48. if first.group_in_firm then num_in_group=1;
  49. else num_in_group+1;
  50. run;
复制代码

藤椅
jungsee 发表于 2015-2-6 00:47:54
谢谢大神指教,我再检查一下,好心人 太多, 膜拜高手!!!

板凳
sushe1527 发表于 2015-2-6 10:17:38
mingfeng07 发表于 2015-2-6 00:14
这个厉害了 看了半天 可是export连续超过4个0适用吗?感觉手动lag4总是不妥

报纸
mingfeng07 学生认证  发表于 2015-2-6 12:26:38
sushe1527 发表于 2015-2-6 10:17
这个厉害了 看了半天 可是export连续超过4个0适用吗?感觉手动lag4总是不妥
恩,确实太粗糙了,所以只适用题中的条件,至于超过4个0,因为首先是考虑连续连个export大于0,然后再考虑连续首次3个0的情况,而3个0后面不管连续多少个0都不会考虑,我是直接删去,所以应该不会影响,可以调试一下看看。

地板
wpfwxn 发表于 2015-2-6 15:37:35
一直受不了那么多汉字

7
jungsee 发表于 2015-2-6 16:11:24
mingfeng07 发表于 2015-2-6 12:26
恩,确实太粗糙了,所以只适用题中的条件,至于超过4个0,因为首先是考虑连续连个export大于0,然后再考虑 ...
连续 4 个0, 没有BUG, 3个0 之后的 0 删除了, 直至 搜索到下一个 正数。

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

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