BookmarkSubscribeRSS Feed
mspak
Quartz | Level 8

Good days to all helpers,

I am user of  Window 7 64 bits with my SAS9.3 64 bits installed into PC. I tried to run the following SAS function to calculate the distance between 2 locations in US as follows:

data distance; set pair;

distance=zipcitydistance(zip, metro_zip);

if distance^=. then output;

run;

zip and metro_zip are two zipcode columns in SAS data file. Both zip (format:  Z5.  informat: None) and metro_zip  (format:  None  informat: None) are stored as numeric variables.

However, unfavourable outcome was obtained. It is stated in log that:

NOTE: Invalid argument to function ZIPCITYDISTANCE at line 3 column 10.

tic=3ATTUF zip=40593 metro_zip=30002 City=AVONDALE ESTATES sum_rank=10 distance=. _ERROR_=1 _N_=1420


The above error was repeated many times in log. 

I hope that anyone can help to solve my problem. I hope to understand the reason of the error message and any suggestions.

Thank you.

mspak

Message was edited by: Renee Harper (I cleaned up your title a bit to make it work better in the notification features.)

11 REPLIES 11
mspak
Quartz | Level 8

All of the zipcodes are based on a reliable US zipcode database and a financial database which firms' zipcodes are based in US.

So, do you think I should use the longitude and latitude to calculate distance instead?

Thank you very much.

art297
Opal | Level 21

The one the function seems to be missing is your base zipcode, 40593.  You could use one that is only 1.8 miles away, namely 40502

mspak
Quartz | Level 8

Hi all,

Thanks for reply. I get my output now. I think some of the zipcodes might be invalid. I have output my data only for those with the valid zipcodes. :smileysilly: 

Darrell_sas
SAS Employee

I was going to suggest that you update your SASHELP.ZIPCODE file with the newest one at http://support.sas.com/mapsonline in the download section.  ZIP Codes change frequently and we place a new data set in the download area every quarter.  These are based on the current USPS ZIP Codes.

But the ZIP Code 40593 isn't valid according to the USPS ZIP Code checker.  It may be one that became obsolete and was dropped.

You can use Proc GEOCODE with METHOD=ZIP or a DATA STEP or PROC SQL to match against the latest SASHELP.ZIPCODE to validate your ZIP Codes.

GraphGuy
Meteorite | Level 14

Sounds like you've got this on basically figured out ... but just in case it might be useful to some of the people reading, here is one (of many) ways to limit the input data to only those zipcodes that are in the sashelp.zipcode table, so the zipcitydistance runs cleanly...

data pair;
input zip metro_zip;
datalines;
27607 27513
40593 27513
;
run;

proc sql;
create table pair as
select * from pair
where zip in (select unique zip from sashelp.zipcode)
and metro_zip in (select unique zip from sashelp.zipcode);
quit; run;

data distance; set pair;
distance=zipcitydistance(zip, metro_zip);
if distance^=. then output;
run;

mspak
Quartz | Level 8

Hi RobertAllison,

Thanks. I should eliminate all the zipcodes that are not included in sashelp.zipcode to avoid from having the same error messages.

zipcitydistance function is ONLY for the zipcode downloaded from SAS. If I have a list of zipcodes with their longitude and latitude which are outside USA. Can I use the same function for distance calculations?

Regards,

mspak

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 11 replies
  • 3016 views
  • 6 likes
  • 5 in conversation