ZIPSTATE Function

Converts ZIP codes to two-character state postal codes.

Category: State and ZIP Code

Syntax

ZIPSTATE(ZIP-code)

Required Argument

ZIP-code

specifies a numeric or character expression that contains a valid 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, ZIPSTATE assumes that the value is 01040.

Details

The Basics

If the ZIPSTATE 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.
ZIPSTATE returns the two-character state postal code (or world-wide GSA geographic code for U.S. territories) that corresponds to its five-digit ZIP code argument. ZIPSTATE returns character values in uppercase.
Note: ZIPSTATE does not validate the ZIP code.

How the ZIP Code Is Translated to the State Postal Code

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.

Army Post Office (APO) and Fleet Post Office (FPO) Postal Codes

The ZIPSTATE function recognizes APO and FPO ZIP codes. These military ZIP codes correspond to their exit bases in the United States. The ZIP codes are contained in the SASHELP.ZIPMIL data set. To determine when this data set was last updated, execute PROC CONTENTS:
proc contents data=SASHELP.ZIPMIL;
run;
Output from the CONTENTS procedure provides the date of the last update, along with the contents of the SASHELP.ZIPMIL data set.
Note: You can download the latest version of the SASHELP.ZIPMIL data set from the Technical Support Web site. Select Zipcode Dataset from the Name column to begin the download process. You must execute the CIMPORT procedure after you download and unzip the data set.

Determining When the State Postal Code Table Was Last Updated

Except for APO and FPO addresses, the SASHELP.ZIPCODE data set contains postal code information that is used with ZIPSTATE and other ZIP code functions. To determine when this data set was last updated, execute PROC CONTENTS:
proc contents data=SASHELP.ZIPCODE;
run;
Output from the CONTENTS procedure provides the date of the last update, along with the contents of the SASHELP.ZIPCODE data set.
Note: You can download the latest version of the SASHELP.ZIPCODE data set from the Technical Support Web site. Select Zipcode Dataset from the Name column to begin the download process. You must execute the CIMPORT procedure after you download and unzip the data set.

Comparisons

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 uppercase 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 upper-case two-character state postal code (or world-wide GSA geographic code for U.S. territories) that corresponds to its five-digit ZIP code argument.

Example

The following SAS statements produce these results.
SAS Statement
Result
state1=zipstate('27511');
put state1;
 
NC
state2=zipstate('01040');
put state2;
 
MA
state3=zipstate(1040);
put state3;
 
MA
state4=zipstate(59017);
put state4;
 
MT
length zip $10.;
zip='90049-1392';
zip=substr(zip,1,5);
state5=zipstate(zip);
put state5;
 
CA