|
|
沙发

楼主 |
发表于 2008-1-9 23:30:01
|
只看该作者
Re: [求助]如何挑数据
data a;
input date time $6. number;
cards;
20050905 070000 15
20050905 070120 13
20050905 070125 18
20050905 070156 13
20050905 070208 9
20050905 070601 17
20050905 070711 10
20050905 070923 21
20050905 071216 15
20050905 080519 12
20050905 170955 11
20050905 172209 15
20050905 173000 8
20050906 070000 13
20050930 173000 15
;
run;
%macro a(date,starttime,interval);
%let date=%sysfunc(compress(&date,%str(%-)));
%let starttime=%str(%')&starttime%str(%'t);
data _null_;
a=%unquote(&starttime);
call symput('starttime',trim(left(a)));
run;
%let interval=%sysevalf(&interval*60);
%let m=%eval(&interval+1);
data temp;
set a ;
xx=hms(substr(time,1,2),substr(time,3,2),substr(time,5,2));
if date=&date and xx>=&starttime;
;
proc sql noprint;
select max(xx) into:max from temp;
quit;
%let n=%sysfunc(ceil(%sysevalf((&max-&starttime)/&interval)));
data temp1;
length type 8;
set temp;
do i=1 to &n;
if &starttime+(i-1)*&m<=xx<=&starttime-1+i*&m then type=i;
end;
drop i;
proc sort data=temp1 out=temp2;
by type;
run;
data result;
set temp2;
by type;
if first.type then output;
drop type xx;
run;
%mend;
%a(20050905,07:00:00,15); |
|