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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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