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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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