Joeyjoejoe
06-26-2009, 05:15 PM
Okay, I got a list of places (Longitude and latitude). Let's call this list A. And another list of places (also with longitude and latitude). Let's call this list B.
For every place in list A, I need to find the closest place in list B.
I don't need help with the equation to find distance. The first thought I had was to match up everything in list A to list B, but that will make one huge file (> billion records).
It seems like making a macro would be the proper solution. The code below will work for one place (with longitude and latitude), but how do I make this into a macro function? I basically need to run this macro as many times as there are rows in the list A. I understand macros, but I don't quite understand how to send values (in this case DISTANCE and PLACE_NAME) back.
%LET LAT1 = -63.6565;
%LET LONG1 = 44.73386;
DATA CLOSEST;
SET LISTB;
DISTANCE = 6378.7 * ARCOS(SIN(&lat1) * SIN(lat) + COS(&lat1) * COS(lat) * COS(lonG - &lonG1));
RUN;
PROC SORT DATA = CLOSEST;
BY DISTANCE;
RUN;
DATA CLOSEST;
SET CLOSEST (OBS = 1);
RUN;
Can anyone help? Thanks.
For every place in list A, I need to find the closest place in list B.
I don't need help with the equation to find distance. The first thought I had was to match up everything in list A to list B, but that will make one huge file (> billion records).
It seems like making a macro would be the proper solution. The code below will work for one place (with longitude and latitude), but how do I make this into a macro function? I basically need to run this macro as many times as there are rows in the list A. I understand macros, but I don't quite understand how to send values (in this case DISTANCE and PLACE_NAME) back.
%LET LAT1 = -63.6565;
%LET LONG1 = 44.73386;
DATA CLOSEST;
SET LISTB;
DISTANCE = 6378.7 * ARCOS(SIN(&lat1) * SIN(lat) + COS(&lat1) * COS(lat) * COS(lonG - &lonG1));
RUN;
PROC SORT DATA = CLOSEST;
BY DISTANCE;
RUN;
DATA CLOSEST;
SET CLOSEST (OBS = 1);
RUN;
Can anyone help? Thanks.