What you are describing are the connected components of a graph with a node for each account and an edge between two nodes if their GEODIST is at most 2. You can calculate connected components by using PROC OPTNET (or the network solver in PROC OPTMODEL) in SAS/OR. The algorithm is O(m), where m is the number of edges. Note that Latitude must be between -90 and 90 for GEODIST, so I changed the -100 to -90.
GEODIST:
http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#n1korpfg2e18lon1nwpow9qijdxe.htm
connected components in PROC OPTNET:
http://support.sas.com/documentation/cdl/en/ornoaug/68159/HTML/default/viewer.htm#ornoaug_optnet_details17.htm
connected components in PROC OPTMODEL:
http://support.sas.com/documentation/cdl/en/ormpug/68156/HTML/default/viewer.htm#ormpug_networksolver_details13.htm
data have;
input Application_id Latitude Longitude;
datalines;
1000009999 -75.0000 50.0000
1000000888 -90.0000 30.0000
1000000777 -75.0000 50.0500
1000000666 -75.0000 50.0400
1000000555 -80.0000 35.0000
1000000444 -75.0300 50.0000
;
proc sql;
create table edges as
select
a.Application_id as from,
b.Application_id as to,
geodist(a.Latitude,a.Longitude,b.Latitude,b.Longitude,'M') as weight
from have as a, have as b
where a.Application_id < b.Application_id
and calculated weight <= 2;
quit;
proc optnet data_nodes=have data_links=edges out_nodes=out_nodes;
data_nodes_var node=Application_id;
concomp;
run;
... View more