BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
deleted_user
Not applicable
(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
ChrisNZ
Tourmaline | Level 20
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
deleted_user
Not applicable
Fantastic - thanks Chris

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1143 views
  • 0 likes
  • 2 in conversation