Say I have the following 4 houses with the distances between them
GHI 35ft ABC 20ft DEF 40ft JKL 100ft XYZ 10 ft WTH
Identifying each neighbor within 40ft is quite simple, however I want to identify each connected neighbor within 40 ft. So here GHI & JKL, ABC & JKL, etc. would all be neighbors as there is always less than or equal to 40 ft between them. XYZ would only be neighbors with WTH.
Essentially I would like the following resulting table
Location 1 - Neighbor 1 - Distance to Neighbor 1 - Neighbor 2 - Distance to Neighbor 2 - Neighbor 3 - Distance to Neighbor 3
ABC - DEF - 20ft - GHI - 35ft - JKL 40ft
DEF - ABC - 20ft - GHI - 35ft - JKL - 40ft
GHI - ABC - 35ft - DEF - 20ft - JKL - 40ft
JKL - DEF - 40ft - ABC - 20ft - GHI - 35 ft
XYZ - WTH - 10ft - - - -
WTH - XYZ - 10ft - - - -
Thanks in advance
You can't solve this problem with distances only, unless you have the distances between every house pairs. It is usually simpler to start with house locations. You can then locate every pair which is within 40ft and use SAS/OR OPTNET to find the connected components of houses within 40ft.
First, select all pairs closer than 40 ft apart, then use my macro at
Good luck!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.