02-24-2012 03:25 AM
I have a list of stores and their location longitude and lattidue. If stores are with 30 miles of each other, they are assigned into the same group. I can write a data step to find out the grouping. I would like to know if I can use some SAS procedure to accomplish this task quickly. Can I use cluser analysis procedures for this?
02-27-2012 01:11 PM
You can, if you translate your lat/long data to UTM coordinates (say X, Y). I did this recently to group samples taken within 50 meters from each other, it looked like:
proc fastclus data=chloro summary radius=50 strict least=max
out=chloroClust outseed=seedClust cluster=Site clusterlabel="Site" noprint;
var x y;
02-27-2012 01:24 PM
Check out the geodist function in SAS as a starting point.
How are specifying 'groups', do all stores have to be less than 30km from each other. Otherwise a store at one edge of the radius could be in another group theoretically...depends on your data of course.
02-27-2012 02:18 PM
I guess a cheap way of doing it using the geoDist function suggested by Reeza would be :
data haveXY(drop=refLong refLat);
retain refLong refLat;
if _n_ = 1 then do;
refLong = long;
refLat = lat;
id = _n_;
x = geodist(lat,refLong,lat,long,"DM");
y = geodist(refLat,long,lat,long,"DM");
proc fastclus data=haveXY summary radius=15 strict least=max
out=wantClust outseed=seedWant cluster=Site clusterlabel="Site" noprint;
var x y;
The first store coordinates are arbitrarly chosen as a reference. The "DM" option means that your coordinates are in degrees and that the distance is returned in miles.