楼主: orainman
1553 3

[原创博文] 下面的代码如何解读 谢了各位 [推广有奖]

  • 0关注
  • 0粉丝

已卖:272份资源

大专生

10%

还不是VIP/贵宾

-

威望
0
论坛币
95 个
通用积分
0
学术水平
0 点
热心指数
2 点
信用等级
0 点
经验
428 点
帖子
30
精华
0
在线时间
46 小时
注册时间
2011-6-19
最后登录
2015-7-31

楼主
orainman 发表于 2011-8-23 13:19:26 |AI写论文
1论坛币
data b;set a;by NPERMNO date type date1;
retain car1;if first.type then car1=ri;else car1=car1*ri;
retain car1_MV;if first.type then car1_MV=rmv;else car1_MV=car1_MV*rmv;
retain car1_ME;if first.type then car1_ME=rme;else car1_ME=car1_ME*rme;
if last.type then output;run;/*

关键词:RETAIN output First outpu type 如何

沙发
yugao1986 发表于 2011-8-23 16:20:19
仅供参考下,感觉可以优化
  1. data b;/*数据b*/
  2. set a;/*读取a,依npermno date type date1排序*/
  3. by NPERMNO date type date1;
  4. retain car1;/*声明car1,在条件语句结束后保持car1的值*/
  5. if first.type then car1=ri;/*条件语句,first.type指排序后的第一个type*/
  6.    else car1=car1*ri;/*不满足first.type的条件*/
  7. retain car1_MV;
  8. if first.type then car1_MV=rmv;
  9.    else car1_MV=car1_MV*rmv;
  10. retain car1_ME;
  11. if first.type then car1_ME=rme;
  12.    else car1_ME=car1_ME*rme;
  13. if last.type then output;/*最后type,则输出*/
  14. run;/*
复制代码
三人行必有我师

藤椅
orainman 发表于 2011-8-23 16:57:49
yugao1986 发表于 2011-8-23 16:20
仅供参考下,感觉可以优化
谢谢你的解读了,我想问一下,这段程序retain car1;if first.type then car1=ri;else car1=car1*ri;,如果有5个type=1观测,那最后显示的结果格式是三个还是五个?谢谢

板凳
yugao1986 发表于 2011-8-23 17:14:30
orainman 发表于 2011-8-23 16:57
谢谢你的解读了,我想问一下,这段程序retain car1;if first.type then car1=ri;else car1=car1*ri;,如果 ...
应该是最后的一个累计结果,你试一试看看.
三人行必有我师

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

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