Zipcode-related Function in SAS & Applications in Proc Gmap

Click to see larger picture |

goptions gunit=pct cback=white htitle=4 htext=3

colors=(PAGY LIY STY DEGY dark_yellow very_dark_yellow ) ;

title1 "US Population in 1990";

proc gmap map=maps.us data=maps.uscity all;

id state;

block pop/levels=6;

choro pop/levels=6;

run; quit;

1) Go to the following page from SAS to download the most updated zipcode Then, click the "Download" link to redirect to: All Archived zipcode datasets, download the one you need.

2) You may need to log in to download the file. After you download the file, unzip it and saved it, then using the CIMPORT procedure to import the file into a SAS data library. For example:

proc cimport file='zipcode.cpt' lib=sashelp; run;

3) From the SASHELP library and rename the new ZIPCODE data set and index from the unique name representing the version of the ZIP code file to be ZIPCODE. For example:

proc datasets lib=sashelp; delete zipcode;

change zipcode_unique=zipcode; run; quit;

Note the you must have write access to the SASHELP library in order to place the data set in the library.

1) Use ZIPCITYDISTANCE function to calculate the distance between two ZIP codes. The syntax is:

2) Use geodist function to calculate the distance:

data _null_; distance1=geodist(30.68, -88.25, 35.43, -82.55); put 'Distance= ' distance1 'kilometers'; distance2=geodist(30.68, -88.25, 35.43, -82.55, 'M'); put 'Distance = ' distance2 'miles'; /* Calculate the Geodetic Distance with Input Measured in Degrees */ data _null_; input lat1 long1 lat2 long2; Distance = geodist(lat1,long1,lat2,long2,'DM'); put 'Distance = ' Distance 'miles'; datalines; 35.2 -78.1 37.6 -79.8 ; run; /* Calculate the Geodetic Distance with Input Measured in Radians */ data _null_; input lat1 long1 lat2 long2; pi = constant('pi'); lat1 = (pi*lat1)/180; long1 = (pi*long1)/180; lat2 = (pi*lat2)/180; long2 = (pi*long2)/180; Distance = geodist(lat1,long1,lat2,long2,'RM'); put 'Distance= ' Distance 'miles'; datalines; 35.2 -78.1 37.6 -79.8 ;run;The actual example in the documentation has two ZIP code values enclosed in single quotes, but function will work with or without quotes around the ZIP codes. If you have an invalid ZIP code (or outdated) in your data, you will receive some error: NOTE: Invalid argument to function ZIPCITYDISTANCE at ...

One convenient code to convert to z5. character zipcode format: zip_char=put(input(STORE_ZIP,8.),z5.); so if zip_num=31 which means zip_char="00031".

Check out the next tutorial to learn more about the applcations of: zipcity(zip),zipstate(zip),zipname(zip),ZIPFIPS(zip). Source: www.sas.com

** Related links: **