Functions and CALL Routines |
Converts ZIP codes to uppercase state names.
Category: |
State and Zip Code
|
-
zip-code
-
specifies a numeric or character expression
that contains a five-digit ZIP code.
Tip: |
If the value of zip-code begins with leading zeros, you can enter the value
without the leading zeros. For example, if you enter 1040, ZIPNAME assumes
that the value is 01040. |
If the ZIPNAME
function returns a value to a variable that has not yet been assigned a length,
by default the variable is assigned a length of 20.
ZIPNAME returns the name of the state or U.S. territory
that corresponds to its five-digit ZIP code argument. ZIPNAME returns character
values up to 20 characters long, all in uppercase.
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.
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. However,
SAS software is updated only with each new release of the product.
The ZIPCITY, ZIPNAME, ZIPNAMEL, and ZIPSTATE
functions accept the same argument but return different values:
-
ZIPCITY returns the mixed-case name of the city
and the two-character postal code that corresponds to its five-digit ZIP code
argument.
-
ZIPNAME returns the upper-case name of the state
or U.S. territory that corresponds to its five-digit ZIP code argument.
-
ZIPNAMEL returns the mixed-case name of the state
or U.S. territory that corresponds to its five-digit ZIP code argument.
-
ZIPSTATE returns the uppercase two-character state
postal code (or world-wide GSA geographic code for U.S. territories) that
corresponds to its five-digit ZIP code argument.
The following SAS statements produce these results.
SAS Statements |
Results |
state1=zipname('27511');
put state1;
|
NORTH CAROLINA
|
state2=zipname('01040');
put state2;
|
MASSACHUSETTS
|
state3=zipname(1040);
put state3;
|
MASSACHUSETTS
|
state4=zipname('59017');
put state4;
|
MONTANA
|
length zip $10.;
zip='90049-1392';
zip=substr(zip,1,5);
state5=zipname(zip);
put state5;
|
CALIFORNIA
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.