idge-实际上它与请求完全匹配。要求只保留在同一小时内有200次或更多观测的记录。您可以使用子查询将其重新表述为联接,但为什么不让SAS自动为您执行此操作?@Tom,为什么不使用having语句呢?无需子查询,无需混乱和缓慢的重新合并。。。。 data
idge-实际上它与请求完全匹配。要求只保留在同一小时内有200次或更多观测的记录。您可以使用子查询将其重新表述为联接,但为什么不让SAS自动为您执行此操作?@Tom,为什么不使用having语句呢?无需子查询,无需混乱和缓慢的重新合并。。。。 data ,sas,Sas,idge-实际上它与请求完全匹配。要求只保留在同一小时内有200次或更多观测的记录。您可以使用子查询将其重新表述为联接,但为什么不让SAS自动为您执行此操作?@Tom,为什么不使用having语句呢?无需子查询,无需混乱和缓慢的重新合并。。。。 data lib.data; set lib.data; retain I; by date hour; if first.date or first.hour then I=1; else I=I+1; run; proc s
idge-实际上它与请求完全匹配。要求只保留在同一小时内有200次或更多观测的记录。您可以使用子查询将其重新表述为联接,但为什么不让SAS自动为您执行此操作?@Tom,为什么不使用
having
语句呢?无需子查询,无需混乱和缓慢的重新合并。。。。
data lib.data;
set lib.data;
retain I; by date hour;
if first.date or first.hour then I=1; else I=I+1;
run;
proc sql;
create table lib.data1
as select a.*, max(I) as N
from lib.data as a
group by date, hour
order by date, hour;
quit;
data lib.data (drop= i n);
set lib.data;
if n < 200 then delete;
run;
data lib.data (drop= counter rc);
set lib.data;
by date hour;
retain counter 0;
If _N_ =1 then do;
declare hash hs(multidata:'yes');
hs.definekey('date','hour');
hs.definedone();
end;
/*if first record in hour zero counter*/
if first.hour then do;
counter=0;
end;
/*increment counter*/
counter = counter+1;
/*if counter less then 200 add record to hash table*/
if counter < 200 then do;
hs.add();
end;
/*if counter=200 output current record and record from hash*/
if counter = 200 then do;
output;
rc = hs.find();
do while(rc=0);
output;
rc= hs.find_next();
end;
end;
/*if counter greater then 200 output current record*/
if counter > 200 then output;
/*if last record in hour clear hash*/
if last.hour then do;
hs.clear();
end;
run;
data want ;
do until (last.hour);
set lib.data;
by date hour;
n=sum(n,1);
end;
do until (last.hour);
set lib.data;
by date hour;
if n >= 200 then output;
end;
run;
proc sql;
create table want as
select
a.*
from
lib.data a
join
(select
date,
hour,
count(*)
from
lib.data
group by date, hour
having count(*) >= 200) b
on
a.date = b.date and
a.hour = b.hour
;
quit;