Help using Base SAS procedures

Efficient data base search

Reply
N/A
Posts: 0

Efficient data base search

Hi -

I've been puzzling over this for some months. I have a work-around that gets the job done, but there has to be a more efficient and slicker way to do this than what I do now (proc sql maybe?).

A genomics application. I have dataset A with a number of observations (10^2 - 10^4). Each observation has a chromosome (1-22) plus starting base and ending base. Call these A, A1, and A2). I have a second dataset, B, with a different set of features but is much larger (10^6-10^7), each with a chromosome and starting and ending base (B, B1, and B2).

Taking the first observation in A, find all rows in B with the same chromosome and with any overlap. There may be more than one. So, a row in B matches if A=B and (A1 le B1 le A2 or A1 le B2 le A2 or B1 le A1 le B2 or B1 le A2 le B2). Repeat for all observations in A.

Is there a fast and elegant way to do this? Many thanks in advance for any hints you might have - PFS
N/A
Posts: 0

Re: Efficient data base search

Posted in reply to deleted_user
(Sorry - email got abbreviated)

So, a row in B matches if A=B and (A1 le B1 le A2 or A1 le B2 le A2 or B1 le A1 le B2 or B1 le A2 le B2). Repeat for all observations in A.

Is there a fast and elegant way to do this? Many thanks in advance for any hints you might have - PFS
PROC Star
Posts: 1,760

Re: Efficient data base search

Posted in reply to deleted_user
2 ways to do this, using either sql or a data step:

data A;
do I=1 to 1e4;
A=int(ranuni(0)*22);
A1=int(ranuni(0)*100000);
A2=A1+10;
output;
end;
run;

data B(index=(B));
do I=1 to 1e6;
B=int(ranuni(0)*22);
B1=int(ranuni(0)*100000);
B2=B1+10;
output;
end;
run;

proc sql; * join using sql;
create table C as
select *
from A
left join B
on A=B and (A1<=B1<=A2 or A1<=B2<=A2 or B1<=A1<=B2 or B1<=A2<=B2);
quit;

sql is a lot faster in this case (30s on my PC) using my data sample.
Hash tables might be faster but the key is not unique and I don't have 9.2 to test.




Message was edited by: Chris@NewZealand

Removed data step
N/A
Posts: 0

Re: Efficient data base search

Fantastic - thanks Chris
Ask a Question
Discussion stats
  • 3 replies
  • 114 views
  • 0 likes
  • 2 in conversation