Data visualization with SAS programming

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC

Reply
Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC

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.)

Respected Advisor
Posts: 3,775

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

If some work and others don't perhaps SASHELP.ZIPCODE does not contain the zip code.

Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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.

Esteemed Advisor
Posts: 7,293

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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

Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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: 

Esteemed Advisor
Posts: 7,293

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

If you decide to look up zip codes that are close to the ones you are missing you might be interested in:

http://www.mapszipcode.com/zip-code-radius

SAS Employee
Posts: 170

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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.

Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

Thank you for suggestion. I did download the SAS zipcode.

Regards,

mspak

SAS Employee
Posts: 967

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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;

Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

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 Employee
Posts: 967

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

If you already have the lat/long of the locations, I would recommend using the geodist() function to calculate the distance...

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003113162.htm

Regular Contributor
Posts: 162

Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANCE Invalid argument to function ZIPCITYDISTANC Invalid argument to function ZIPCITYDISTANC

Thanks for suggestions.

mspak

Ask a Question
Discussion stats
  • 11 replies
  • 1050 views
  • 6 likes
  • 5 in conversation