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

Hello experts!

 

I have 2 datasets - a Customer dataset and a Retailer dataset.

 

Customer address information has a column named Custzip which has the Zipcode for each customer.

The retailer has many stores across US and the Retailer dataset has a column named StoreZip which has the Zipcode for each store.

For each customer, I need to compute the distance between the customer and all the stores of the retailer and then select the zipcode which has the least distance (the nearest store for that customer). I want to use the zipcitydistance function provided by SAS to compute distances.

 

For example, say CustZip looks like this:

 

IDCustZip
199212
292882
398058
48810
529901
692637
792336
892008
993730
1090224
1180015
1294401
1391776
1410514
1597221
1685338
1798119
1893271
1984004
2060137

 

And StoreZip looks like this: 

 

IDStoreZip
133146
295678
392101
495128
597086
660173
748083
855425
910601
1011590
1144124
1297015
1397204
1419406

 

The final output needs to enhance the Custzip structure and add the columns: NearestStoreZip and Distance (as computed by zipcitydistance).

 

Please let me know if my query is not very clear. I am using SAS 9.4 and any help will be deeply appreciated.

 

Thanks!

Arko.

1 ACCEPTED SOLUTION
4 REPLIES 4
arkapravo
Calcite | Level 5
Thank you so much for the prompt response!! The link provided appears very helpful. I will try to implement and get back, if necessary.
manoelcunha
Calcite | Level 5

Does this code work with the Brazilian zipcode? I have to find the distance between two zipcode of Brazil
Reeza
Super User
No, that would work for US. If you have the centroids for each zip code your can use the Geodist function though.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1576 views
  • 2 likes
  • 3 in conversation