Sample 24809: Converting ZIP Codes to State Names
SAS provides a variety of State & ZIP functions that convert ZIP codes to state names and state postal codes. The sample code below illustrates three State & ZIP functions.
|
data a;
x=zipname('27511');
put x=;
y=zipnamel('27511');
put y=;
z=zipstate('27511');
put z=; run;
/* Results of PUT statements written to the log. */
x=NORTH CAROLINA
y=North Carolina
z=NC
|
The ZIPNAME, ZIPNAMEL, and ZIPSTATE functions take the same argument but return different values:
- ZIPNAME returns the uppercase name of the state or U.S. territory that corresponds to its five-character ZIP code argument.
- ZIPNAMEL returns the upper- and lowercase name of the state or U.S. territory that corresponds to its five-character 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-character ZIP code argument.
Other State and ZIP code functions provided by SAS include:
- FIPNAME which converts FIPS codes to state names in uppercase
- FIPNAMEL which converts FIPS codes to state names in uppercase and lowercase
- FIPSTATE which converts FIPS codes to two-character postal codes
- STFIPS which converts state postal codes to FIPS state codes
- STNAME which converts state postal codes to state names (all uppercase
- STNAMEL which converts state postal codes to state names in uppercase and lowercase
- ZIPFIPS which converts ZIP codes to FIPS state codes
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data a;
x=zipname('27511');
put x=;
y=zipnamel('27511');
put y=;
z=zipstate('27511');
put z=; run;
/* Results of PUT statements written to the log. */
x=NORTH CAROLINA
y=North Carolina
z=NC
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample shows how to use SAS functions to convert ZIP codes to state names and state postal codes.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> State and ZIP Code
|
| Date Modified: | 2006-01-11 03:03:01 |
| Date Created: | 2004-10-08 08:14:43 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |