全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1742 2
2014-07-14
如题,data structure 是按照一个日期一条观测,需要找到连续三天的观测,求大神给个sample macro!
二维码

扫码加我 拉你入群

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

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

全部回复
2014-7-15 11:33:14
复制代码
二维码

扫码加我 拉你入群

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

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

2014-7-28 04:43:39
A simple SQL will do it if a data set is small. The first solution is slight better.

Both solutions involve a Cartesian product join which will cause a performance issue if the data set has more than 10 thousands  rows. If this is a case, a more efficient way will be a data step.


data tmp;
/*   do date='1jan1980'd to '31jan2014'd;*/
   do date='1jan2014'd to '31jan2014'd;
      if ranuni(123)>0.3 then output;
        end;
        format date yymmdd10.;
run;


proc sql;
  create table tmp2 as
  select a.date , b.date as date2
  from tmp a join tmp b on (b.date=a.date or b.date=a.date+1 or b.date=a.date+2)
  group by 1
  having count(a.date)=3
  order by 1,2
  ;
  quit;

proc sql;
  create table tmp2 as
  select a.date , b.date as date2
  from tmp a , tmp b
  where 0<=(b.date-a.date)<=2
  group by 1
  having count(a.date)=3
  order by 1,2
  ;
  quit;


二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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