|
这个可以实现..应该没理解错你的意思了吧..程序还可以简化...还有,使用有个要求,第一列是唯一的,如果不唯一还得改一下程序。
data test1;
input d1 d2;
cards;
20050429 20050322
20070430 20070331
20070403 20050201
20050325 20050223
20050427 20050425
20050510 20050423
;
run;
data test2;
input d ;
cards;
20050429
20070430
20070403
20050325
20050427
20050510
;
run;
data _null_;
length d1 8 count 8;
if _n_=1 then do;
declare hash h1(ordered:'n');
h1.definekey('d1');
h1.definedata('d1','d2','count','d');
h1.definedone();
call missing(count,d1,d2,d);
count=0;
declare hiter iter1('h1');
end;
if _n_=1 then do;
declare hash h2(dataset:'test2');
h2.definekey('d');
h2.definedata('d');
h2.definedone();
call missing(d);
declare hiter iter2('h2');
end;
do while(not last1);
set test1 end=last1;
rc0=h1.ref();
end;
rc1=iter1.first();
do while(rc1=0);
count=0;
h1.replace();
rc2=iter2.first();
do while(rc2=0);
if d2<d<d1 then do;
count+1;
h1.replace();
end;
rc2=iter2.next();
end;
rc1=iter1.next();
end;
h1.output(dataset:'result2');
run;
|