BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have two text files A.txt & B.txt

A.txt has 100 observations
B.txt has 200 observations

For every observation in A, I need it to look through every observation in B and return the closest match based on the complev function.

Is there a simple way to do this?
4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12
Simple depends on your skill set....

first, read the data into SAS datasets.
second, write a SQL SELECT statement to do the join.
third, address records in a with two or more matches in b.

Three simple steps. But if you have never used SQL it is not so simple. Something like

SELECT a., b., complev(on a and b)
FROM a, b
WHERE MIN(complev(on a and b)) > 0;

I've not tried this code, but that is where I would start.

Note that, as MIN is a summary function and used in the WHERE clause, this is a Cartesian product "under the hood" so it does not scale well. It's OK for 100x200, but would take forever for 100,000x200,000.
RPGarland
Calcite | Level 5
I wrote this without SQL, I read everything all the words as seperate variables instead of observations. It outputs dvar1-dvar100 which correspond to atxt vars 1-100 and has values of the the btxt vars that are closest to these atxt vars.

data atxt;
set atxt (rename=(var1-var100=avar1-avar100));
n=_n_;
run;

data btxt;
set btxt (rename=(var1-var200=bvar1-bvar200));
n=_n_;
run;

data textfiles (keep=dvar1-dvar100);
merge atxt btxt;
by n;
array avars $ avar1-avar100;
array bvars $ bvar1-bvar200;
array eddis cvar1-cvar200;
array mindis dvar1-dvar100;
do i = 1 to dim(avars);
mindist=999;
do j = 1 to dim(bvars);
eddis=complev(avars,bvars);
if eddis mindis=j;
mindist=eddis;
end;
end;
end;
run;
RPGarland
Calcite | Level 5
Sorry it clipped my data step, it ends:

mindis=j;
mindist=eddis;
end;
end;
end;
run;
deleted_user
Not applicable
"if eddis; end; end; end; run;" so it should end like this?

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!

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.

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