Hi I have a table that I created using proc sql;
I have the latitude and longitude values for a single location (A) and then in the table I created, I have the latitude and longitude values for every address in the table. I am trying to create a flag that marks specific people within 5 miles or 10 miles from location A.
Can anyone tell me how I can create another column in the table I created that calculates the distance in miles for each row compared to the single location (A)?
If you are asking for straight-line distance and not road distance you can use the GEODIST function.
If this is really for just one point compared with others than you could hard code the single location into the function call and just use the other data set as the source.
The code would look like:
data want; set have; /*this has the addresses of interest*/ distance = geodist(fixedLat, FixedLong, addressLat, addressLong,'M'); run;
actually to go with the function you specify whether the lat and long are in Degrees or Radians by using "DM" or "RM". The M says the result will be in miles.
Fixedlat and Fixedlong are the lat and long of the one point you want to use with all the records.
GEODIST(latitude-1, longitude-1, latitude-2, longitude-2 <,options> )
If you are asking for straight-line distance and not road distance you can use the GEODIST function.
If this is really for just one point compared with others than you could hard code the single location into the function call and just use the other data set as the source.
The code would look like:
data want; set have; /*this has the addresses of interest*/ distance = geodist(fixedLat, FixedLong, addressLat, addressLong,'M'); run;
actually to go with the function you specify whether the lat and long are in Degrees or Radians by using "DM" or "RM". The M says the result will be in miles.
Fixedlat and Fixedlong are the lat and long of the one point you want to use with all the records.
thank you,
I tried this (fake target lat/long):
%let target_lat = 12.00000;
%let target_long = -40.0000;
data want;
set *table with all the addresses*;
distance = geodist(&target_lat, &target_long, latitude, longitude, 'M');
where latitude and longitude are the column names in the table with all the addresses.
Unfortunately this code runs but it only gives the following columns: distance, latitude, longitude, longitude and they are all blanks.
nevermind I had the wrong table referenced, this solved it - thank you!
@aarnold18 wrote:
nevermind I had the wrong table referenced, this solved it - thank you!
I've used SAS for over 30 years. If you believed me when I said that I never used the wrong data set I would be looking for that deed I have to the Brooklyn Bridge to sell it to you. 😉
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.