%let pgm=read_TL_faces; filename pgm "&pgm..sas"; /* Read the TIGER/Line faces DBF files that relate blocks to various geocodes. Oct. 2018: Only adding CD115s, SLDUs and SLDLs! Data from ftp2.census.gov/geo/tiger/TIGER2017/FACES/ Nov. 2018: Adding County18, cousubfp18, placefp18. Data from ftp2.census.gov/geo/tiger/TIGER2018/FACES/ */ options NOmprint; %include '/pub/sas/autoexec.sas'; %let tgrpath=%str(/home/riceg/geocorr_adds/tgrlnfaces); libname out '/home/riceg/geocorr_adds/out'; libname user '/home/riceg/geocorr_adds/temp'; libname sf1 '/pub/data/sf12010' access=readonly; libname popests '/pub/data/popests' access=readonly; %let _resort=0; %let st=01; %let stab=al; x cd &tgrpath ; %global firstco; %let firstco=1; %*-- Gets set to 0 within the doco macro after processing first county of a state ; %macro doco(fipco,cname); %global firstco; x unzip -q tl_2018_&county._faces.zip tl_2018_&county._faces.dbf ; filename dbfin "&tgrpath/tl_2018_&county._faces.dbf"; proc import datafile=dbfin dbms=dbf replace out=user.&pgm ; getdel=no; run; x rm tl_2018_&county._faces.dbf ; *-- Free up space. We still have the data inside the .zip file ; filename dbfin clear; %let countychanged=0; data %if &firstco %then %str(&stab.tgrlnfaces); %else %str(c&fipco.faces); ; set user.&pgm (keep=statefp10--suffix1ce countyfp cousubfp placefp Atotal); %let _state=%substr(&fipco,1,2); where statefp10="&_state"; *-- added to prevent missing blocks; length state $2 County $5 cnty $3 Tract $7 Block $4 blksfx $1; State=statefp10; *cnty=countyfp; *-- initially did this just for VA, but actually it works for all of them; cnty=countyfp10; County=state||countyfp10; cousubfp18=cousubfp; placefp18=placefp; Tract=substr(tractce10,1,4)||'.'||substr(tractce10,5,2); Block=blockce10; blksfx=suffix1ce; * We keep county18 since we have two instances (independent city 51515 going back to be part of 51019) where counties changed ; county18=state||countyfp; if county18 ne county then call symput('countychanged','1'); if (county18 ne county) and (county ne '02270') and (county ne '46113') then do; county18=county; end; keep State--placefp18 county18 Atotal; run; /* We have now created the dataset for this county. If it is the first county we write directly to the state set. For all counties after the 1st we write to a temporary c&fipco.faces set and then we use proc append to add it to the state dataset. */ %if &firstco=0 %then %do; proc append base=&stab.tgrlnfaces data= c&fipco.faces; run; %end; %let firstco=0; %mend doco; /* *-- Do a test county run here: ; options mprint; %let firstco=1; %let county=01001; %doco(01001,Autauga); options NOmprint; */ data uscom16; set popests.uscom16; keep state county areaname; format county $5.; run; %macro doit(state,stab); data _null_; file stdout; put "out.&stab.tgrlnfaces is being processed."; run; %let st=&state; %global firstco; %let firstco=1; %***docos(state=&st,mac=doco,codataset=sf1.uscounties); %docos(state=&st,mac=doco,codataset=user.uscom16); proc sort data=&stab.tgrlnfaces; by county tract block blksfx; run; data user.facecodes; set &stab.tgrlnfaces; by county tract block blksfx; if first.blksfx then do; nfaces=1; SumAtotal=Atotal; end; else do; nfaces+1; SumAtotal + Atotal; end; if last.blksfx; drop atotal; run; proc sort; by county tract block descending SumAtotal; run; data out.&stab.tgrlnfaces; set user.facecodes; by county tract block; if first.block; *-- Because we sorted descending, the first obs has the greatest value ; drop nfaces sumAtotal; run; data _null_; file stdout; put "out.&stab.tgrlnfaces has been created."; put ; run; %mend doit; /* Comment out ================================= %*-- Do full run beginning 10/30/2018: ; %dostates(01 02 04 05 06 08 09 10 11 12,msgs=1); %dostates(13 15 16 17 18 19 20 21 22 23 24 25 26 27 28,msgs=1); %dostates(29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47,msgs=1); %dostates(48 49 50 53 54 55 56,msgs=1) ; %dostates(51,msgs=1) ; *-- On July 1, 2013 the indpependent city of Bedford, VA became a town and rejoined Bedford County. So 51515 is gone! We have to make sure we do not try to process a tigrnln file for that defunct county. Also means we have a 2010 and a 2014 county. ; *-- In 2015 there were two county name and FIPS code changes AK: 02270 Wade Hampton Census Area became 02158 Kusilvak Census Area SD: 46113 Shannon became 46101 Oglala Lakota ; ================================= End commented out */ %dostates(46,msgs=1) ;