BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rkdubey84
Obsidian | Level 7
This one is awesome it takes less than 1 second to run and get the desired results of HI & LO .

But it is not counting all the frequencies between that 5 minute & 1 minute time interval. It is showing Count5 is only 14 for the 5 minute time interval.
Ksharp
Super User

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;
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 3612 views
  • 8 likes
  • 5 in conversation