BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
aarnold18
Calcite | Level 5

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)?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19
GEODIST(latitude-1, longitude-1, latitude-2, longitude-2 <,options> )
ballardw
Super User

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.

 

aarnold18
Calcite | Level 5

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. 

 

 

 

aarnold18
Calcite | Level 5

nevermind I had the wrong table referenced, this solved it - thank you!

ballardw
Super User

@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. 😉

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1192 views
  • 0 likes
  • 3 in conversation