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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.