x cd /pub/data/corrlst/Tools; %let pgm=us_zip2010_cntyplace; filename pgm "&pgm..sas"; *---Create an equivalency dataset linking 2010 ZCTA5 values with counties and places. 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. Running for entire us, 01-12. John Blodgett, OSEDA, U. of Missouri Outreach & Extension ---*; title 'Creating a National ZCTA (2010) to County/Place 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--afact; 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 _statenm ; if placefp=' ' then PlaceNm='Outside any place'; length Stab $2; stab=put(state,$fipstab2.); label afact='Portion of ZCTA5 pop in this place/county'; run; proc sort data=zipcoplc; by zcta5 descending pop2010; run; data corrlst.us_zip2010_cntyplace(compress=yes label='2010 ZIP Code to Place/County Equivalency'); set zipcoplc(in=in1 ) zipcoplc(in=in2); by zcta5; if first.zcta5 then do; ZipTotPop=0; Nparts=0; Primary=1; retain Primary; end; *---If we get here it is the second pass and we want to process and keep---; if in1 then do; ZipTotPop + pop2010; Nparts+1; delete; end; *---On first pass we just aggregate to get total pop for the ZIP-; PctPop=100*Pop2010/ZipTotPop; output; Primary=0; *---this flag is 1 for the first obs asspciated with the ZCTA which means the one with largest Pop2010 value.---; label Primary='Flag Indicating Primary Intersection' Pctpop='Pop2010 as % of ZipTotPop'; format Primary 2. PctPop 5.1; run; proc print data= corrlst.us_zip2010_cntyplace (where=(state='29' and zcta5=:'65')); by zcta5; id zcta5; title2 "Mo Subset"; run;