Pretty simplistic, but you could do this. I wouldn't recommend this with anything much larger than what you have -- in your data, the CROSS JOIN will produce a table with 1M rows (5000*200), which is fine.
data pt;
do pt=1 to 20;
visited_hosp=rand('integer',1,10);
X=rand('erlang',2)*5;
Y=rand('erlang',2)*10;
output;
end;
run;
data hosp;
do hospid=1 to 10;
hosp_X=rand('erlang',2)*5;
hosp_Y=rand('erlang',2)*10;
output;
end;
run;
proc sql;
create table pthosp as
select a.*, b.hospid,
geodist(a.Y, a.X, b.hosp_Y, b.hosp_X) as dist
from
pt A
cross join
hosp B
order by a.pt, dist;
quit;
data want;
set pthosp;
by pt;
if first.pt;
hosp_match='N';
if visited_hosp=hospid then hosp_match='Y';
run;
proc print data=want; run;
... View more