****************************************************************************************************
****************************************************************************************************
* PROGRAM: addstatetozip3.sas
* Created (mm/dd/yyyy): 08/09/2017
*--------------------------------------------------------------------------------------------------
* PURPOSE: The macro adds state based on 3 Digit Zip Code.
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro addstatetozip3(data=);
%put =====> MACRO CALLED: addstatetozip3;
/* recode the following 3 digit zips:
These 3 digit zip codes correspond to multiple states as of 1/1/2017. If new discordant states
arise, a warning will be written to the log. The decision was made to assign to 1 state */
if zip3 = '063' then statecode = 'CT';
if zip3 = '205' then statecode = 'DC';
if zip3 = '739' then statecode = 'OK';
if zip3 = '834' then statecode = 'ID';
if zip3 = '969' then statecode = 'GU';
create table ziplookup as
select distinct zip3, statecode
%put WARNING: Due to 3 zip codes mapping to multiple states, the following 3 digit zip codes have been recoded:
1) 063 = CT, 2) 205 = DC, 3) 739 = OK, 4) 834 = ID, 5) 969 = GU;
/*Check to ensure no additional states need to be reclassified*/
create table _recodedstates as
select zip3, count(zip3) as zip_count
having zip_count > 1 and zip3 not in ('063', '205', '739', '834', '969');
%ISDATA(dataset=_recodedstates);
%if %eval(&nobs. > 1) %then %do;
%put WARNING: Additional 3 digit zip codes map to multiple states. Further investigation recommended.
See output dataset for these zip and state codes;
data output.discrepant_states;
proc sql noprint undo_policy=none;