楼主: superyxo
1286 3

[问答] 请各位帮忙验证一下代码 [推广有奖]

  • 2关注
  • 1粉丝

硕士生

64%

还不是VIP/贵宾

-

威望
0
论坛币
91 个
通用积分
1.0005
学术水平
7 点
热心指数
2 点
信用等级
2 点
经验
9870 点
帖子
93
精华
0
在线时间
199 小时
注册时间
2007-8-28
最后登录
2021-4-15

楼主
superyxo 发表于 2013-10-9 12:31:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我的数据(have)包括银行(LenderID),贷款公司(BorrowerID),以及LenderID和BorrowerID之间交易的日期(Date)。数据按照BorrowerID LenderID Date排序,如下数据片段所示。我想做的是创建一个新变量relation,对于每一个交易(Date),如果同一对LenderID和BorrowerID在之前五年内还有另外的交易(Date),那么relation等于1,其他等于0,像下边数据里的relation一样。我用下边的代码试了试,随机挑了几个结果是对的,想请各位验证下,帮忙看看有没有没想到的情况。多谢多谢另外下边的代码还报错
“NOTE: Invalid argument to function YRDIF at line 46 column 29.”
“NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 404500 at 46:29”但是结果还是对的
  1. data want1;
  2. set have;
  3. format lagdate YYMMDDN8.;
  4. by borrowerid lenderid;
  5. lagdate = lag(date);
  6. if first.lenderid then lagdate = .;
  7. run;


  8. data want2;
  9. set want1;
  10. relation = 0;
  11. if not missing(lagdate) and yrdif(lagdate, date, 'ACT/ACT') le 5 then relation = 1;
  12. run;
复制代码




BorrowerIDLenderIDDaterelation

1

7827

19870912

0

2

5951

19870901

0

2

6003

19870908

0

3

6127

19871001

0

4

5930

19870801

0

4

6128

19870801

0

6

5951

19871001

0

7

5951

19870901

0

8

6225

19951004

0

8

6833

19871001

0

9

6039

19871201

0

9

6834

19871001

0

10

6100

19870912

0

10

6100

19880630

1

11

5891

19871012

0

12

6075

19870909

0

13

6039

19880202

0

13

7878

19880201

0

14

6149

19871001

0

15

5875

19870902

0

16

6835

19870912

0

17

30195

20011019

0

17

69495

20011019

0

17

80167

20011019

0

17

82462

20011019

0

18

5891

19871012

0

18

5891

19880831

1

19

5891

19921123

0

19

5891

19931231

1

19

6003

19870612

0

19

6031

19921123

0

19

6531

19931231

0

19

7839

19870901

0

20

5893

19870912

0

20

5893

19881215

1

20

5978

19940722

0

20

6529

19930820

0

20

6901

19870101

0

21

7827

19871001

0

22

7845

19870212

0

22

7845

19871001

1

23

6006

19871001

0

23

6006

19871101

1

23

6842

19871001

0

24

1468

19900801

0

24

1468

19970120

0

24

1468

20001211

1

24

1468

20041215

1

24

1468

20041217

1

24

5862

19910405

0

24

5862

19920310

1

24

5862

19920414

1

24

5862

19920507

1

24

5862

19960105

1

24

5862

19961210

1

24

5862

19970110

1

24

5889

19871001

0

24

5889

19871118

1

24

5889

19910405

1

24

5889

19940311

1

24

5889

19960105

1

24

5889

19961210

1

24

5889

19970110

1

24

5889

20001211

1

24

5893

19901207

0

24

5893

19910405

1

24

5893

19940311

1

24

5893

19960105

1

24

5893

19961210

1

24

5893

19970110

1









二维码

扫码加我 拉你入群

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

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

关键词:请各位帮忙 Mathematical mathematica Operations Mathematic performed following function relation 贷款

沙发
tangliang0905 发表于 2013-10-9 13:20:19
data want2里面如果是对同一组borrowid和lenderid作比较的话,要先sort,然后加上by 语句吧
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
superyxo + 1 + 1 + 1 热心帮助其他会员

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

藤椅
superyxo 发表于 2013-10-9 21:34:53
tangliang0905 发表于 2013-10-9 13:20
data want2里面如果是对同一组borrowid和lenderid作比较的话,要先sort,然后加上by 语句吧
好像不用再sort和by了?data want1里已经用过by,把每组borrowerid和lenderid的第一个lagdate的值设为missing了。data want2里lagdate是missing的就跳过了,只有不是missing(lagdate)和 yrdif(lagdate,date,'act/act')小于等于5的才设置relation=1
稍微改了一下代码,已经不报错了:
  1. data want1;
  2. set have;
  3. format lagdate YYMMDDN8.;
  4. by borrowerid lenderid;
  5. lagdate = lag(date);
  6. if first.lenderid then lagdate = .;
  7. run;


  8. data want2;
  9. set want1;
  10. relation = 0;
  11. if not missing(lagdate) then do;
  12.      if yrdif(lagdate, date, 'ACT/ACT') le 5 then relation = 1;
  13. end;
  14. run;
复制代码





板凳
tangliang0905 发表于 2013-10-9 22:27:56
没错,就是lagdate是空值的时候,导致yrdif这个function报错的

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

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