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

Hello,

I have SAS 9.4.

I am trying to measure the distance between two cities. 

I have HQ_ZIP variable and Affiliate_ZIP variable. 

For example, 

HQ_ZIP  AFF_ZIP

12345     98765  

34567     87654

67890     76362

34543     65432

 

I want a new variable that measures the distance between HQ_ZIP and AFF_ZIP

I tried;

    distance = zipcitydistance ( HQ_ZIP, AFF_ZIP)

but it did not work. 

Help would be very appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Per the documentation, it looks like the ZIPCITYDISTANCE function works for recognized ZIP codes in the United States. Many of those you provided (or made up?) are not in the U.S.  The SASHELP.ZIPCODE dataset contains which ZIP codes are valid:

proc contents data=sashelp.zipcode;
run;

So make sure those that you're using are valid.

 

Here is an example that works, using ZIPCITYDISTANCE(), for valid U.S. zip codes:

data have;
    input HQ_ZIP AFF_ZIP;
    datalines;
10001 90001
98101 32789
;
run;

data want;
    set have;
    distance = zipcitydistance(HQ_ZIP, AFF_ZIP);
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Please provide more information about "did not work". Show us the log (the entire log for this DATA step, including code, ERRORs, WARNINGs, NOTEs). If there appear to be errors in the output, show us and explain why you think it is not working.

--
Paige Miller
mklangley
Lapis Lazuli | Level 10

Per the documentation, it looks like the ZIPCITYDISTANCE function works for recognized ZIP codes in the United States. Many of those you provided (or made up?) are not in the U.S.  The SASHELP.ZIPCODE dataset contains which ZIP codes are valid:

proc contents data=sashelp.zipcode;
run;

So make sure those that you're using are valid.

 

Here is an example that works, using ZIPCITYDISTANCE(), for valid U.S. zip codes:

data have;
    input HQ_ZIP AFF_ZIP;
    datalines;
10001 90001
98101 32789
;
run;

data want;
    set have;
    distance = zipcitydistance(HQ_ZIP, AFF_ZIP);
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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