turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Efficient data base search

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-18-2010 05:51 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-18-2010 05:53 PM

(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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-18-2010 08:59 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-19-2010 08:13 AM

Fantastic - thanks Chris