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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.