x cd /pub/data/mable14/Tools; %let pgm=temptgrlnfaces29019; filename pgm "&pgm..sas"; *---Read the TIGER/Line "faces" dbf files that related blocks to various geocodes. Looking at detail for Boone County as possible debugging aid. jgb, 9-10-15. John Blodgett, OSEDA, MCDC, ---*; libname library (sasctlgs); *---the docos macro accesses the $county format code in library.formats-----; %let tgrpath=%str(/pub/data/mable14/tgrlnfaces); libname mable14 '/pub/data/mable14'; libname user '/SAS_temp/userb'; %let _resort=0; %let st=29; %let stab=mo; x cd &tgrpath ; %*let county=29019; %*macro doco(fipco,cname); %global firstco; %let fipco=29019; %let cname=Boone; %let county=&fipco; x unzip -q tl_2014_&county._faces.zip tl_2014_&county._faces.dbf ; filename dbfin "&tgrpath/tl_2014_&county._faces.dbf"; proc import datafile=dbfin dbms=dbf replace out=user.&pgm ; getdel=no; run; x rm tl_2014_&county._faces.dbf ; *---free up space. We still have the data inside the .zip file--; filename dbfin clear; data facecodes; set work.&pgm (keep=statefp10--blockce10 suffix1ce uace10 pumace10 statefp countyfp tractce blkgrpce cousubfp placefp elsdlea scsdlea unsdlea cd114fp sldust sldlst ); length state $2 County $5 cnty $3 Tract $7 Block $4 blksfx $1 UA $5 UR $1 PUMA12 $5; *---We shall save space by not keeping these --14 vars but we do need to put them in later because a few have changed--; **length state14 $2 County14 $5 cnty14 $3 tract14 $7 bg14 $1 ; **Decided not to keep these**; length cousubfp14 $5 placefp14 $5 SDElm14 SDSec14 SDUni14 SDbest14 $5 SDbesttype14 $1 cd114 $2 County14 $5 sldu14 sldl14 $3; *<---note adding county14------------; State=statefp10; cnty=countyfp10; County=state||cnty; Tract=substr(tractce10,1,4)||'.'||substr(tractce10,5,2); Block=blockce10; blksfx=suffix1ce; *We keep county14 since we have had an instance (independent city 51515 going back to be part of 51019) where county changed-; county14=statefp||countyfp; retain _countychanged 0; if county14 ne county then _countychanged+1; if _countychanged=1 then call symput('countychanged','1'); **State14=statefp; ** cnty14=countyfp; ** County14=state14||cnty14; **Tract14=substr(tractce,1,4)||'.'||substr(tractce,5,2); ** BG14=blkgrpce; cousubfp14=cousubfp; placefp14=placefp; SDElm14=elsdlea; SDSec14=scsdlea; SDUni14=unsdlea; *---bestsd is new for this cycle. There are 3 school dists but they are mutually exclusive in MO and other states. So we used this to store the relevant code. SDbesttype contains letters u, e or s to indicate type of district in SDbest-; if sduni14 ne ' ' then do; sdbest14=sduni14; sdbesttype14='u'; end; else if sdelm14 ne ' ' then do; sdbest14=sdelm14; sdbesttype14='e'; end; else if sdsec14 ne ' ' then do; sdbest14=sdsec14; sdbesttype14='s'; end; cd114=cd114fp; UA=uace10; PUMA12=pumace10; if UA=" " then UR="R"; else UR="U"; label UR="Urban/Rural"; sldu14=sldust; sldl14=sldlst; keep State--sldl14; run; %let lnfaceCodes=placefp14 cousubfp14 SDbest14 SDbesttype14 sldu14 sldl14; %let curBasecodes=State14 county14 tract14 bg14; proc sort; by county tract block blksfx ; run; *--and now sort by the target codes as well--; *---Extra step inseerted new for 2014. We look for duplicate blocks (signaled by blksfx values) and keep the version which occurs most frequently.---; data maxn_blksfxs; set facecodes; by county tract block blksfx; where blksfx ne ' '; if first.block then do; _na=0; _nb=0; _nc=0; _nd=0; _nother=0; end; if blksfx='A' then _na+1; else if blksfx='B' then _nb+1; else if blksfx='C' then _nc+1; else if blksfx='D' then _nd+1; else do; _nother+1; _savesfx=blksfx; end; if last.block then do; _max=_na; blksfxmax='A'; if _nb > _max then do; _max=_nb; blksfxmax='B'; end; if _nc > _max then do; _max=_nc; blksfxmax='C'; end; if _nd > _max then do; _max=_nd; blksfxmax='D'; end; if _nother > _max then blksfxmax=_savesfx; output; end; keep county tract block blksfxmax; run; data facecodes2(label="With lower count blksfxs deleted"); merge facecodes(in=in1) maxn_blksfxs(in=in2); by county tract block; if in2 then if blksfx=blksfxmax; *<---this is the filter saying we only keep data for one suffix code--; drop blksfxmax; run; *----and now eliminate dups after filtering out the non-max alternatives---; proc sort data=facecodes2 nodupkey out=c29019faces; by county tract block; run; %**doco(29019,Boone);