全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1927 8
2010-09-02
data a;
  input company date:yymmn6. sales;
  format date yymmn6.;
  datalines;
1001 200509 20
1001 200603 30
1016 200603 451
1016 200606 521
1016 200609 358
1016 200612 650  
;
run;
proc sort data=a;
by company date;
run;
data c;
set a;
by company date;
if _n_=1 then date2=date;
else date2=lag(date);
y=intck("month",date2,date );
run;

这里面为什么date2第二行是有缺失值的?请教,谢谢!
二维码

扫码加我 拉你入群

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

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

全部回复
2010-9-2 09:52:47
努力回帖 勤工俭学
二维码

扫码加我 拉你入群

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

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

2010-9-2 10:18:28
SAS HELP:
The queue for LAGn is initialized with n missing values, where n is the length of the queue (for example, a LAG2 queue is initialized with two missing values). When LAGn is executed, the value at the top of the queue is removed and returned, the remaining values are shifted upwards, and the new value of the argument is placed at the bottom of the queue. Hence, missing values are returned for the first n executions of LAGn, after which the lagged values of the argument begin to appear.
你的代码当_N_=2首次执行,故此时return的为缺失值。一般调用lagn队列都是在初始就赋给一个变量,再进行操作。
二维码

扫码加我 拉你入群

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

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

2010-9-2 10:25:21
一般不在条件语句中使用lag函数
二维码

扫码加我 拉你入群

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

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

2010-9-2 10:27:25
先赋值,再使用,多注意点,就可以了......
二维码

扫码加我 拉你入群

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

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

2010-9-2 10:43:32
data a;
  input company date:yymmn6. sales;
  format date yymmn6.;
  datalines;
1001 200509 20
1001 200603 30
1016 200603 451
1016 200606 521
1016 200609 358
1016 200612 650  
;
run;
proc sort data=a;
by company date;
run;
data c;
set a;
by company date;
retain date2;
date2=lag(date);
if _n_=1 then date2=date;
y=intck("month",date2,date );
run;
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群