OK. Assuming the interval between two neighbour obs always be one minute.
proc import datafile='/folders/myfolders/acc_test.txt' out=have dbms=tab replace;
run;
proc sql;
create table key as
select dtm1,max(tradeprice) as max,min(tradeprice) as min,count(tradeprice) as count
from have
group by dtm1;
quit;
data want;
if _n_=1 then do;
if 0 then set key;
declare hash h(dataset:'key');
h.definekey('dtm1');
h.definedata('max','min','count');
h.definedone();
end;
set have;
call missing(max,min,count);
k=dtm1+'00:01:00't;
rc=h.find(key:k);
L1=min;H1=max;COUNT1=count;
count5=0;
do i=0 to 5;
call missing(max,min,count);
k=dtm1+'00:01:00't*i;
rc=h.find(key:k);
L5=min;H5=max;COUNT5+count;
end;
drop i k rc max min count;
run;
The final lesson that needs to be taken from this:
While proc sql allows to achieve a lot of things in one seemingly simple step, it often disguises the fact that the operation behind it can be very complex. On top of that, the optimizer in SAS SQL is not on par with what full-fledged RDBMS's can do, so you end up with code that has the performance of watching paint dry. Especially with spinning disk storage, those issues become very pronounced.
Everytime you run into SQL performance problems, try to dissect the operation into smaller steps and run them on their own, using the proper SAS tool (eg proc sort), and you might find performance increases of several orders of magnitude.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: