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.
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;
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.