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!
Here's an example from last week:
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.
@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!
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.
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.
Yes but it does not say how to calculate the distance.
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;
@Reeza Someone went red! 🙂
@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 😞
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 25. Read more here about why you should contribute and what is in it for you!
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.