x cd /pub/data/blkrel10/Tools; %let pgm=cnvt_blkrel2010; filename pgm "&pgm..sas"; *----Accesses a block 2000 to block 2010 relationship file collection (as posted to the web by the Census Bureau geo. division early 2011 and FTPed from http://www.census.gov/geo/www/2010census/t00t10.html circa 2-14-11. Merges this data with data from the latest mable database (mable09 - 2000 block based). Creates a series of geographic equivalency data sets per state and generates the tractrelation_reports directory of pdf reports. John Blodgett, OSEDA, U. of Missouri Outreach & Extension Initial coding Feb/Mar, 2011 Adding more 2k geos to the state data sets. Running 2-4-12 with filter removed: if substr(blk2k,2,2)='99' . ----*; %let datapath=%str(/pub/data/blkrel10/); **filename files pipe "unzip -p -l &datapath.mo.zip"; *<--list the files inside (did not work, ignore the "-l"--; title "Census 2000 to Census 2010 Geographic Relationship Report" ; libname blkrel10 '/pub/data/blkrel10'; libname pl942010 '/pub/data/pl942010'; **libname user '/SAS_temp/userb'; %libname(mable09); *****libname mable10 '/pub/data/mable10'; *---Part 2 once wrote some data sets here, where we relate 2010 blks to selected 2k geos---; %let state=10; %let stab=de; *------------------------------------Part 1: Create the 2000 to 2010 relationship and correlation list sets / reports---------*; %macro xcode; County2k=state2k||cnty2k; County=state||cnty; label tract2k='Tract 2000' tract='Tract 2010' afact='Tract 2k to Tract 10 alloc factor'; drop cnty2k cnty; Keep county county2k; %mend xcode; %macro doit(state,stab); filename in pipe "unzip -p &datapath.TAB2000_TAB2010_ST_&state._v1.zip " ; ***Step A***; data &stab.blks (compress=no) blkrel10.&stab.xstate(label="Blocks crossing &stab state line" compress=no) ; infile in dsd missover lrecl=255 firstobs=2 termstr=crlf obs=max; *--the input recs were a constant 250 bytes (padded)--; * length state $2 cnty2k $3 tract2k $7 blk2k $4 pflag2k $1 state2k $2 cnty2k $3 tract2k $7 blk2k $4 pflag2k $1; length state2k $2 cnty2k $3 tract2k $7 blk2k $4 blksfx2k $1 AreaLand2k AreaWater2k 5 pflag2k $1 state $2 cnty $3 tract $7 blk $4 blksfx $1 AreaLand AreaWater 5 pflag $1 AreaLandInt AreaWaterInt 5; input state2k -- AreaWaterInt; substr(tract,5,3)='.'||substr(tract,5,2); *--edit 950100 to 9501.00--; substr(tract2k,5,3)='.'||substr(tract2k,5,2); *if substr(blk2k,2,2)='99' and state=state2k then output blkrel10.&stab.wblks; * else ---; if state=state2k then output &stab.blks; else output blkrel10.&stab.xstate; label tract='2010 Tract' blk='2010 Block' AreaLand='Land Area 2010 Blk (Sq Mtrs)' AreaWater='Water Area 2010 Blk' AreaLandInt='Area of 2000/2010 block Intsx'; run; proc sort data= pl942010.&stab.sums(keep=sumlev cnty tract block totpop tothus where=(sumlev='750') rename=(block=blk )) out=pl94sorted; by cnty tract blk; run; *---At this point we want to add several variables from the 2010 pl94 data set to this: namely the pop10 and hus10 data items. We do the merge by 2010 county, tract and block of 2 data sets not sorted by these variables, by defining indices on both the relevant sets.---; proc sql; create view &stab.blksSorted as select * from &stab.blks order by cnty, tract, blk; quit; ***Step D***; data &stab.blocks2; merge &stab.blksSorted(in=inclist) pl94sorted (keep=SumLev cnty tract blk TotPop TotHUs rename=(Totpop=Pop10 TotHUs=HUS10) in=inpl94); by cnty tract blk; if not (inclist and inpl94) then do; _nbad+1; if _nbad <= 50 then put cnty= tract= blk= inclist= inpl94= ; if inclist; end; drop SumLev _nbad; run; proc sort data=&stab.blocks2 out=&stab.blks; by state2k cnty2k tract2k blk2k; run; ***Step F***; data blkrel10.&stab.blks(sortedby=cnty2k tract2k blk2k label='2k to 2010 census blk relationship + mable09' compress=Yes); merge &stab.blks (in=inblkrel) mable09.&stab.blks07(in=inmable keep=cnty tract block pop2k hus2k ur ur90 puma5 vtd taz placefp cousubfp rename=(cnty=cnty2k tract=tract2k block=blk2k ur=ur2k puma5=puma2k vtd=vtd2k taz=taz2k placefp=placefp2k cousubfp=cousubfp2k )) end=last; by cnty2k tract2k blk2k; ****** Comment out for rerun 2-4-2012 jgb ******* if substr(blk2k,2,2)='99' then delete; *===debug===; ** if cnty='001' and substr(blk2k,2,2)='99' then put "No longer filtered: " cnty= tract= blk=; if not inmable then _nomable+1; else if not inblkrel then _noblkrel+1; if last then put /'**** missing data counts**** ' _nomable= _noblkrel= ; attrib afactLand length=4 label='Allocation factor based on land intersectn' format=5.3; if arealand2k then afactLand=AreaLandInt/AreaLand2k; attrib Pop2kInt length=4 label='Est 2k Pop in Intersectn Per afactLand ' format=6.1; if pop2k then Pop2kInt=pop2k*afactLand; else Pop2kInt=0; drop _nomable _noblkrel; **abel blkno='MABLE 09 blkno'; run; ***Step G***; *---create a block 2k to block 2010 correlation list (equivalency file)----; %corrwt(setin=blkrel10.&stab.blks,geocds1=state2k cnty2k tract2k blk2k, geocds2=state cnty tract blk, wtvar=Pop2kInt,keepwt=1, afacts=1, exitout=xcode, setout=blkrel10.&stab.bl2k_bl10 ); ***Step H***; *---create a tract2k to tract10 correlation list (equivalency file)----; %corrwt(setin=blkrel10.&stab.blks,geocds1=state2k cnty2k tract2k, geocds2=state cnty tract, wtvar=Pop2kInt,keepwt=1, afacts=1, exitout=xcode, setout=blkrel10.&stab.tr2k_tr10 ); run; ***Step I***; options nodate; ods pdf file="/pub/data/blkrel10/tractrelation_reports/&statenm..pdf" style=sasweb notoc columns=2; title2 "Tract 2K to Tract 2010 Equivalencies for State of &statenm"; proc print data= blkrel10.&stab.tr2k_tr10 label; by county2k; id county2k; format county2k $county.; var tract2k tract pop2kint afact; footnote h=1 'Report by Mo Census Data Center Using Census Bureau Block Relationship Files as Source'; footnote2 h=1 "The equivalency data for this report is stored in blkrel10.&stab.tr2k_tr10 data set in MCDC public archive"; run; ods pdf close; *<====This Part2 code has been "macroed out". We now do this is mable10/Tools/usblk10_2kgeos since it writes a mable10 set-----; %macro Part2 ( ); *---this step was run once but the results were modified. ******See code in mable10/Tools/usblk10_2kgeos.sas***** ---; *<------------------------- PART 2: Create mable10 datasets linking 2010 blocks to various 2k geos. Generat CSV files as well.--; ***Step 2A***; proc sort data=blkrel10.&stab.blks out=blks2 ; by cnty tract blk arealandint areawaterint; run; ***Step 2B***; data mable10.&stab.blk10_2kgeos(sortedby=cnty tract blk label='2010 block to "primary" 2000 geographies' compress=Yes); length State $2 cnty $3 tract $7 blk $4 blksfx $1 Pop10 HUs10 5; set blks2; by cnty tract blk; *if substr(blk,2,2)='99' then delete; if last.blk; *---We keep the intersection with the largest AreaLandInt and if that is a tie then we use areawaterint to break it-; length bg2k $1; bg2k=substr(blk2k,1,1); run; ***Step 2C***; filename dlmout "/pub/data/mable10/&stab.blk10_2kgeos.csv"; %cnvtdlm(setin=mable10.&stab.blk10_2kgeos, names=1, charvars=state cnty tract blk cnty2k tract2k bg2k puma2k cousubfp2k placefp2k vtd2k taz2k ur2k ur90, quotes=0,hquotes=0, numvars=arealandint) run; %mend Part2; %mend doit; options NOmprint; %**dostates(n=51,names=1); %*ostates(29,names=1); run; *-----------------------------------Part 3: -----------------------------------------------------------------; *----This phase does not need to rerun. If and when it does we may need to tweak the code since we slightly changed the variables on the blk2k_blk10 data set (replacing county with cnty variables). ---; *-----In this section we create the XXpoptrend2010blks data set with estimated 2k pop and pl94-based 2010 pop counts for current (i.e. 2010) blocks and with 2010 placefp and cousubfp codes. ---*; %macro doit(state,stab); proc sort data=blkrel10.&stab.bl2k_bl10(keep=county tract blk pop2kint) out=&stab.temppops; by county tract blk; run; %agg(aggin=&stab.temppops,aggout=pop2k_2010blks, aggby=county tract blk, aggvars=pop2kint, naggvars=1, debug=0); *---so now we have a data set with 2010 geos and 2k total pop counts aggregated. We now want to merge this our 2010 pl94 data and add some geocodes to create an aggin data set which we shall then use to create a whole hierarchy of summaries : county-tract-bg-block . ---; proc sort data= pl942010.&stab.sums(keep=state stab sumlev county tract block totpop tothus placefp cousubfp where=(sumlev='750') rename=(block=blk )) out=pl94sorted; by county tract blk; run; data aggin; merge pop2k_2010blks(in=in1) pl94sorted(in=in2010); by county tract blk; retain state "&state" stab "&stab"; if not in1 then TotPop2k=0; else TotPop2k=round(pop2kint); length bg $1; bg=substr(blk,1,1); label totpop='Total 2010 Pop' tothus='Total 2010 HUs'; drop sumlev pop2kint; run; proc means data=aggin noprint; id state stab; class county tract bg blk placefp cousubfp; types county * tract * bg *blk *cousubfp * placefp county*tract*bg county*tract county placefp county*placefp county*cousubfp ( ) ; var totpop tothus totpop2k ; output out=freqout sum=; run; data blkrel10.&stab.poptrend2010blks blkrel10.&stab.poptrend2010bgtrcopl(drop=blk); length State $2 County $5 SumLev $3; set freqout; select (_type_); when(63) SumLev='100'; *---census block summary but with placefp and cousbfp carried along--; when(56)SumLev='150'; when(48)SumLev='140'; when(32)SumLev='050'; when(0) SumLev='040'; when(2) SumLev='160'; when(34)SumLev='155'; when(33)SumLev='060'; end; *-- drop _freq_ _type_; if sumlev='100' then output blkrel10.&stab.poptrend2010blks; else output blkrel10.&stab.poptrend2010bgtrcopl; drop _type_ _freq_; run; %mend doit; %*dostates(n=51) ; %dostates(29,names=1);