Thanks, Doc. That's sort of the approach I'm going with.
Can anyone confirm that the zipstate function feeds off of SASHELP.ZIPCODE directly? I try to update the ZIPCODE table in HELP from SAS's website (http://support.sas.com/rnd/datavisualization/mapsonline/html/misc.html) as soon as they become available. However, I'm seeing some major discrepancies when comparing the results of ZIPSTATE versus SASHELP.ZIPCODE. The online doc states the following:
"The SASHELP.ZIPCODE data set contains postal code information that is used with the ZIPSTATE and other ZIP code functions. This data set is updated with each new release of SAS software."
Is this true for manual updates after a software release as well? I'm seeing 7 state differences between the two sources. Also, if you loop from 0 to 99999 and feed it to zipstate, it assigns a state to 95,760 zipcodes whereas my current sashelp.zipcodes has 42,085.
Thinking about it some more ZIPSTATE returning more zipcodes with states than SASHELP.ZIPCODE is making sense. I would imagine the latter is only active zips at that size. ZIPSTATE would return a state for any zipcode that's ever been active. Let's say this theory is accurate and explains the difference in zipcode count.
It still doesn't explain differences in state assignment to a zipcode if zipstate is feeding off of sashelp.
/*zipcode sashelp_state zipstate_state*/
/*20588 MD DC*/
/*20598 VA DC*/
/*83414 WY ID*/
/*96595 CA */
/*96598 CA */
/*96599 CA */
/*96939 PW GU*/
The reason that ZIPSTATE returns more codes than are in the table is in the documentation that I referenced:
"To determine which state corresponds to a particular ZIP code, this function uses a zone table that consists of the start and end ZIP code values for each state. It then finds the corresponding state for that range of ZIP codes. The zone table consists of start and end ZIP code values for each state to allow for exceptions, and does not validate ZIP code values."
It also documents why you find differences in location over time.
"With very few exceptions, a zone does not span multiple states. The exceptions are included in the zone table. It is possible for new zones or new exceptions to be added by the U.S. Postal Service at any time. "
Thanks again. For anyone that's interested, this is what I ended up doing. There are no errors in the log for invalid arguments and it actually runs a little faster than the function straight up. Below is the code I used as a base and then my code.