```Date: Wed, 6 Nov 2002 11:54:17 -0700 Reply-To: Jack Hamilton Sender: "SAS(r) Discussion" From: Jack Hamilton Subject: Re: More problems with distances between cities (SASprogrammingaspects) Comments: To: flom@NDRI.ORG Content-Type: text/plain; charset=US-ASCII It would be useful to have a Haversine distance function built into the base SAS product. If that's something you want, send a note to suggest@sas.com. I've suggested it, but didn't get the impression that SAS Institute thinks anyone but me wants it. -- JackHamilton@FirstHealth.com Manager, Technical Development METRICS Department, First Health West Sacramento, California USA >>> "Peter Flom" 11/06/2002 10:27 AM >>> Frank Regarding distances, a purely Euclidean approach isn't exactly right, because the Earth is round. It doesn't make much difference since the continental US is not a large part of the Earth, but since the person I am working with is a geographer, it should be right, for form's sake. This can be corrected using the Haversine formula, but that's not too problematic, I just need to write the code (it's a messy formula, with lots of versions, but do-able). Regarding the matrix of all distances......no doubt a macro is possible, but my skills aren't up to it.....I think the approach I am using will work, but am not sure of the modification that is needed. Peter >>> Frank Lui 11/06/02 12:45PM >>> Just wondering (I did not follow your earlier question and answers). I did not read your codes but just some ideas. If you have x and y coord, why can't you calculate distance between two points directly? I was thinking of: The Distance = Squareroot((square(x2-x1)+square(y2-y1)). Correct me if I made mistakes. As for the calculation of all distances cross all cities, you may need to write a macro. In each macro step, you can build a new data set by picking one city from your data base, renaming x, y coord as different variable names and merging back with your original. Then you can calculate the distances between this city to all cities (will be zero when it comes to itself). Rename (or automatically) the distance to distance_city_one (or other you'd like). For the second city, merge it with data with distances calculated for the first city. Continue this pattern for the third city and so on. You would build a matrix of distance. HTH, Frank ```

Back to: Top of message | Previous page | Main SAS-L page