BookmarkSubscribeRSS Feed
raajdesaii
Fluorite | Level 6

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!

7 REPLIES 7
Reeza
Super User

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!


 

raajdesaii
Fluorite | Level 6

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. 

Reeza
Super User

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. 


 

raajdesaii
Fluorite | Level 6

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

Reeza
Super User

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;

 

ChrisNZ
Tourmaline | Level 20
Reeza
Super User

@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 😞

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 7 replies
  • 1024 views
  • 1 like
  • 3 in conversation