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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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