## SAS GEODIST function

Occasional Contributor
Posts: 10

# SAS GEODIST function

Hello SAS Community, this is my first time posting here.

I have been trying to get distances between two locations. One is a hospital with a particular zipcodes for eg.20015, and others are 100 patients with different zipcodes. I have latitudes and longitudes for all the zipcodes to get the straight line distance. I have been trying to look online and read on SAS website on how to about performing this. Can anyone help with an example of a SAS code in a particular situation?

Thanks!

Super User
Posts: 23,987

## Re: SAS GEODIST function

Here's an example from last week:

https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-combine-spatial-and-attribute-data-...

It's not zipcode but similar idea. I believe there's also a ZIPCITYDISTANCE function that will take the two zip codes and calculate the distance.

http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#n1r333fdkro...

raajdesaii wrote:

Hello SAS Community, this is my first time posting here.

I have been trying to get distances between two locations. One is a hospital with a particular zipcodes for eg.20015, and others are 100 patients with different zipcodes. I have latitudes and longitudes for all the zipcodes to get the straight line distance. I have been trying to look online and read on SAS website on how to about performing this. Can anyone help with an example of a SAS code in a particular situation?

Thanks!

Occasional Contributor
Posts: 10

## Re: SAS GEODIST function

Thank you for your reply and the link to the thread. Those threads would let me manually input the zipcodes and that would be possible if i have limited number of observations. In my case, I have 100 observations and the zipcodes are from the same variable so I am not sure how to write the code.

Super User
Posts: 23,987

## Re: SAS GEODIST function

Those are examples of how to create data for demonstration purposes so that anyone, anywhere can take them and run them to see how it works.

The concept is the exact same, except your table 1 and table 2 are the SAME table.

raajdesaii wrote:

Thank you for your reply and the link to the thread. Those threads would let me manually input the zipcodes and that would be possible if i have limited number of observations. In my case, I have 100 observations and the zipcodes are from the same variable so I am not sure how to write the code.

Occasional Contributor
Posts: 10

## Re: SAS GEODIST function

Yes but it does not say how to calculate the distance.

Super User
Posts: 23,987

## Re: SAS GEODIST function

Did you run the code? Or check the output, and the variable created from the GEODIST function?

raajdesaii wrote:

Yes but it does not say how to calculate the distance.

proc sql;

create table dist_table as

select h.id, h.lat2 as lat_facility, h.lon2 as long_facility,

h.region,

c.cluster, c.lat1 as lat_cluster, c.lon1 as long_cluster,

geodist(h.lat2, h.lon2, c.lat1, c.lon1, 'k' ) as dist_km

from clusters as c cross join health_facility as h

where c.region=h.region

order by h.id, c.cluster, dist_km;

quit;

Super User
Posts: 2,505

## Re: SAS GEODIST function

@Reeza Someone went red!

Super User
Posts: 23,987

## Re: SAS GEODIST function

@ChrisNZ lol, I would prefer a yellow back ground highlighter to be honest...but red is what the eye will pick up faster. I've tried blue and green and they don't show up as well

Discussion stats
• 7 replies
• 141 views
• 1 like
• 3 in conversation