x cd /pub/data/corrlst/Tools; %let pgm=us_zip2010_state; filename pgm "&pgm..sas"; *---Create an equivalency dataset linking 2010 ZCTA5 values with states. Input is a csv file generated using Geocorr 2010 version at https://mcdc.missouri.edu/MableGeocorr/geocorr2010.html . We specified Zipcides as Source geo and County, Place as target with 2010 pop as weight variable. We used it in setup to create zip2010_cntyplace and now we are just tweaking the setup to do it at the state level. Running for entire us, 08-12. John Blodgett, OSEDA, U. of Missouri Outreach & Extension ---*; title 'Creating a National ZCTA (2010) to State Correlation List'; options nodate; libname corrlst '/pub/data/corrlst'; filename csvin "/pub/data/corrlst/uszip20102cntyplace.csv"; data zipcoplc; infile csvin dsd lrecl=512 firstobs=2 termstr=crlf; length ZCTA5 $5 ZCTAName $40 State $2 _statenm $32 _County $5 _CntyName $32 _PlaceFP $5 _PlaceNm $40 Pop2010 4 _afact 8; input ZCTA5--pop2010; if zcta5 =' ' then do; *---there are some blocks that are not assigned a ZCTA value. We assign these the pseudo-value 99999.--; zcta5='99999'; zctaname='Area with no ZCTA/ZIP assigned'; end; drop _: ; length Stab $2; stab=put(state,$fipstab2.); run; *---aggregate by zip and state---; %agg(setin=zipcoplc,setout=zipstate, aggby=zcta5 state, idvars=stab, aggvars=pop2010, debug=0); proc sort data=zipstate; by zcta5 descending pop2010; run; data corrlst.us_zip2010_state(compress=no label='2010 ZIP Code to State Equivalency' sortedby=zcta5); set zipstate(in=in1 ) zipstate(in=in2); by zcta5; if first.zcta5 then do; ZipTotPop=0; Nparts=0; Primary=1; retain Primary; end; if in1 then do; ZipTotPop + pop2010; Nparts+1; delete; end; *---On first pass we just aggregate to get total pop for the ZIP-; *---If we get here it is the second pass and we want to process and keep---; PctPop=100*Pop2010/ZipTotPop; output; Primary=0; *---this flag is 1 for the first obs associated with the ZCTA which means the one with largest Pop2010 value.---; label Primary='Primary State Flag' Pctpop='Pop2010 as % of ZipTotPop'; format Primary 2. PctPop 5.1; drop _: ; run; proc datasets library=corrlst nolist; modify us_zip2010_state; index create state; quit;