x cd /pub/data/mable14/Tools; %let pgm=genmable14_finalmerge; filename pgm "&pgm..sas"; *----work in progress... we need to incorporate the latest (2015) cbsa data and the tgrlnfaces data for 14. ------------; *--Generate the mable14 data base as used in the geocorr14 web application. This module processes the geographic headers data using the SF1 2010 datasets as source. It merges that basic data with two other block level datasets as created in previously run setups usblk10_2kgeos (to get some 2k geocodes) and read_tgrnlnfaces (to get latest post-2010 (2014 to be precise) geographic codes such as UA, PUMA12, cd114, placefp14, cousubfp14, SD<..>14, sldu14, sldl14. --; /* Update History 08-17-15: Begin coding. Modeled after mable14 module of same name. We change how we incorporate the old 2k data set with puma2k and pop2k. Not keeping other 2k variables this cycle. Incorporating a new cocds data set w 2015 cbsa def. We do nhave any tract-level growth factors from Proximity 1 or new MO library districts. We add extra pre-step to generate a custom mable14.cbsacos15 data set. We deal there with issue of a county defn change in VA (Bedford county absorbed Bedford independent city in 2014 but we split them. 1-26-16: Discovered bug in code to merge the mable14.XXblks10_2kgeos data (puma2k and totpop2k). Rerunning data. 2-25-16: Found problem with CBSA code for Fairmont, MN so rerunning that state. (with regencocds1=1 specified) 8-08-16: Adding hsa and hrr health cre region codes from Dartmouth. See corrlst/Tools/usblocks2hsahrr.sas . 9-01-16: Adding code to get Over65 as new weight variables. Accesses the blocks data sets in sf12010x. 9-10-15: Running for all states to add over65 and hsa, hrr . */ %let geovars=state stab County tract block bg cnty cntysc cousubfp cousubsc placefp placesc placecc concit aianhh anrc necta nectadiv cnecta ua uatype cd111 cd113 sldu12 sldl12 vtd zcta5 sdelm sdsec sduni lsadc hrr hsa arealand areawatr Pop100 HU100 IntPtlat Intptlon Landsqmi areasqmi; %let t=T; *--for test set to a value of T. For production set to null.----; *---we have run a fix on the cbsacos15 data for Arkansas so we will be redefining county codes set for Arkansas. --; %let regencocds1=1; *<=====================if specified, leaves block level sets alone but redoes cocds1 and the view---; %let viewonly=0; %let cogeovars= sumlev county cnty state stab region division FuncStat lsadc Pop100 Hu100; *options msglevel=i fullstimer; options fmtsearch=(mable14 sasctlgs work); libname mable14 '/pub/data/mable14'; libname mable14 '/pub/data/mable14'; libname sf1 '/pub/data/sf12010'; libname sf12010x '/pub/data/sf12010x' access=readonly; libname xxgeos '/pub/data/sf12010/xxgeos'; libname georef '/pub/data/georef' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; %let state=29; %let stab=mo; %let state=20; %let stab=ks; proc format library=mable14; value $SC2Alph '00'=' ' 01-04='A' 05-08='B' 09-11='C' 12-13='D' 14-15='E' 16-17='F' 18='G' 19-20='H' 21-23='I'; value $alphasc a,A='Less than 200' b,B='200-999' c,C='1000-2499' d,D='2500-9999' e,E='10,000-24,999' f,F='25,000-99,999' g,G='100,000-249,999' h,H='250,000-999,999' i,I='1,000,000+' ' '='Not in a place'; run ; *----We begin by creating a slightly edited version of the georef.cbsaco15----*; data mable14.cbsacos15alt(label="Edited to split Bedford County into pre-2014 defn"); set georef.cbsacos15 ; fipco14=fipco; if fipco='51019' then do; *--We got the 6466 estimate value from our popests.ussc14 data set (value would not display via QuickFacts at Bureau site)-; popjl14=popjl14- 6466; output; *--This is the old defn without the Beford City pop which we subtract; fipco='51515'; county=fipco; popjl14=6466; output; *--this is the old Bedford (Independent) city---; end; else output; *--all other counties just copy as-is --*; keep state fipco cbsa metrodiv county csa cbsatype Year PopJL14 Central; ***NO! DO NOT rename cbsa=cbsa15 metrodiv=metrodiv15 csa=csa15 Central=Central15 cbsatype=cbsatype15; run; proc sort; by state fipco; run; options mprint; %macro doit(state,stab); %global regencocds1; %if ®encocds1 %then %goto cocds1; %global viewonly; %if &viewonly %then %goto defineview; /* ========================begin comment (lready ran for all states)==================================== proc sort data=sf1.&stab.blocks(keep=&geovars) out=xxgeos.&stab.blkgeos; by county tract block; run; *---The block level datasets were not sorted (!) so we do this--; ==========================end comment====================================== */ data cdslds2012; set corrlst.uscdslds2012; where state="&state"; %*--see the setup to create the corrlst.uscdslds2012 in corrlst/Tools/ --*; length cnty $3; cnty=substr(county,3,3); run; *--the corrlst set with hrr and hsa uses esriid instead of county tract and block. So we have to create a new version here--; data hsahrr&state; set corrlst.usblocks2hsahrr; length cnty $3 Tract $7 block $4; where state="&state"; cnty=substr(esriid,3,3); tract=substr(esriid,6,4)||'.'||substr(esriid,10,2); block=substr(esriid,12,4); run; proc sort; by state cnty tract block; run; *---Create the block level dataset. New for this cycle we include the XXblks10_2kgeos variables puma2k and pop2k so we do not have to access these data (stored in the mable14 data dir) as part of the view definition. --; *--cnty not on the sf12010x so we create a subset with it added--; data sf1xv/view=sf1xv; set sf12010x.&stab.blocks(keep=state county tract block over65); *<--ADDing var over65 from sf12010x--; length cnty $3; cnty=substr(county,3,3); drop county; run; proc sort data=sf1xv out=sf1x; by state cnty tract block; run; data mable14.&stab.blks&T (sortedby=county tract block index=(county)); merge xxgeos.&stab.blkgeos mable14.&stab.blk10_2kgeos(in=inblks2 keep=state cnty tract blk puma2k TotPop2k rename=(blk=block TotPop2k=Pop2k)) sf1x(in=insf1) cdslds2012 (in=in2 where=(state="&state")) hsahrr&state(in=inhsahrr) %if &state=29 %then %do; mable14.moblk2libdist(in=in3 keep=state cnty tract block libdcode) %end; ; by state cnty tract block; *<---last cycle we had county instead of cnty. But county not on blk10_2kgeos set-; where cnty ne ' '; *---occurs in the blk10_2kgeos sets for a dozen states--*; if _n_=1 and state ne "&state" then do; put //'*******Dataset Problem: State Code read is ' state " but parm value specified is &state"; abort abend; end; *----we drop popden, not worth it. "Macro out" this code.---; %macro popden; retain PopDen '0 Empty'; if pop100=0 then PopDen='0 Empty'; else if areasqmi=0 then PopDen=' '; else do; *--the 7.5 and 6723 break points were the 10th and 90th percentiles of block densities for MO blocks with pop (in 2k census)-; PoppSQMI=Pop100/AreaSQMI; if poppsqmi<=7.5 then PopDen='1 Low'; else if poppsqmi le 6723 then PopDen='2 Med'; else PopDen='3 High'; end; %mend popden; *---New this cycle: create the SDBest10, SDbesttype10 variables with a single type of school district code----; length SDbest10 $5 SDbesttype10 $1; *--recode 2010 school districts changing 99999 to blanks. Need this for sdbest logic to work--; if sduni='99999' then sduni=' '; if sdelm='99999' then sdelm=' '; if sdsec='99999' then sdsec=' '; if sduni ne ' ' then do; sdbest10=sduni; sdbesttype10='u'; end; else if sdelm ne ' ' then do; sdbest10=sdelm; sdbesttype10='e'; end; else if sdsec ne ' ' then do; sdbest10=sdsec; sdbesttype10='s'; end; keep sdbest: ; *--Recode CntySC and PlaceSC into 10 intervals with alpha codes--; CntySC=put(CntySC,$SC2Alph2.); PlaceSC=put(PlaceSC,$SC2Alph2.); format CntySC PlaceSC $alphasc.; keep cd113 ; *** sldl12 sldu12; *--from corrlst.uscdslds2012--; keep sldl12 sldu12; *<--putting back for test 11-19-15--; keep puma2k pop2k; *--from mable14.&stab.blk10_2kgeos--; keep cntysc placesc; keep county tract block state cnty placefp cousubfp bg cd111 sldu sldl vtd zcta5 AreaSQMI LandSQMI Pop100 HU100 IntPtLat IntPtLon SDElm SDSec SDUni; *** TAZ; length placece $4 cousubce $3; keep placece cousubce; keep hsa hrr over65; length _arg $7 _arg2 $10; _arg=state||placefp; if placefp='99999' then placece='9999'; else placece=put(_arg,$fplccnv.); _arg2=county||cousubfp; cousubce=put(_arg2,$fmcdcnv.); label placece='Census Place Code' cousubce='Census County Subd. code'; length InPlace $1; *<--Indicates if in an incorporated place(1), a CDP(2) or not in a place(3).-; if placefp='99999' then InPlace='3'; else if placecc=:'C' then InPlace='1'; else InPlace='2'; keep InPlace; label Inplace='Indicates incorporated, CDP or not in a place'; keep necta nectadiv cnecta; label necta='New England City and Town Area 2010' nectadiv='NECTA Divsion 2010' cnecta='Combined NECTA 2010'; %if %index(09 23 25 33 44 50,&state) ne 0 %then %do; *---We use to have the above keep statement as optional. --; %end; %if &state=29 %then %str(keep libdcode;); label Pop100='Total Pop, 2010 census' hu100='Total HUs, 2010 census'; rename Pop100=pop10 HU100=hus10; run; %cocds1: *---Create the county level set with codes that do not vary within a county---; *---Aug 2013 we modify code so that we merge in the latest cbsa and metdiv codes from georef.cbsacos13--; *---Sep 2015 we modify to add merging the latest cbsa codes effective July 1, 2015----; data mable14.&stab.cocds1&T(label='County level geocodes from SF1 2010' sortedby=county index=(county)); merge sf1.&stab.inventory(where=(SumLev='050' and geocomp='00') keep=&cogeovars geocomp cbsa csa cbsasc metdiv rename=(cbsa=cbsa10 csa=csa10 cbsasc=cbsasc10 metdiv=metdiv10)) %if &state=29 %then %do; georef.mocogeos(keep=county ded_region rpc dot umx2 aaa rename=(ded_region=ded umx2=uoe)) %end; georef.cbsacos13(in=incbsas where=(state="&state") keep=state cbsa metrodiv county csa cbsatype Central rename=(cbsa=cbsa13 metrodiv=metdiv13 csa=csa13 cbsatype=cbsatype13 central=central13)) mable14.cbsacos15alt(in=incbsas15 where=(state="&state")); by county; PopGrowthFactor=PopJL14/Pop100; format PopGrowthFactor 6.3; **retain PopGrowthFactor; %if &state=29 %then %str( format county $5. ded $3. dot $2.; ); rename Pop100=CoPop10 HU100=CoHUS10 FuncStat=CoFuncStat lsadc=CoLsadc region=Reg division=Div; rename Year=CBSAYr PopJL14=coPopJL14; rename metrodiv=metdiv; label cbsa='CBSA current as of CBSAyr' csa='CSA current as of CBSAyr' metrodiv='MetDiv current as of CBSAyr' cbsatype='CBSA type (metro/micro) as of CBSAyr' Central='Central county of CBSA as of CBSAyr'; label year='CBSA/related codes are as of July, this year'; label PopGrowthFactor='Pop Growth Factor per 2014 co pop est'; drop sumlev geocomp; run; %defineview: *---This view combines (merges) the block level data from previous step, block level data from the TIGER Line faces files (see setup read_tgrnlnfaces.sas in this Tools library), and the cocds1 county level data. Note that you can update any of these 3 datasets without having to update this view. ---*; data mable14.&stab.v&T/view=mable14.&stab.v&T; merge mable14.&stab.blks(in=inblks1) /* <=== We moved reference to this data set up to incorporate the 2 new 2k variables into the &stab.blks data set. mable14.&stab.blk10_2kgeos(in=inblks2 keep=state cnty tract blk TotPop2k cnty2k tract2k cousubfp2k placefp2k vtd2k taz2k ur2k ur90 puma2k rename=(blk=block TotPop2k=Pop2k)) */ mable14.&stab.tgrlnfaces(in=inblks3 ); by state cnty tract block; if first.cnty then set mable14.&stab.cocds1&T(rename=(county=countyck)); if county ne countyck then do; put "***Error***: county code on &stab.cocds1 dataset does not match that on the blks datasets****" county= countyck=; call symput('dataproblem',"Error detecting processing mable data for state &stab"); stop; end; /*<=========================Comment out===================================== if not (sldl10_ck=' ' and sldl='999') then if (sldl10_ck ne sldl) then do; _nerr+1; if _nerr le 50 then put "***Check on sldl code fails: " _all_; else abort abend; call symput('dataproblem',"Error detected processing mable data for state &stab"); end; ===========================End commented out================================ */ if placefp14=' ' then placefp14='99999'; *--for consistency with placefp (2010)---; if cbsa10 ne '99999' and cbsa10 ne ' ' then do; CbsaSC10=put(CbsaSC10,$SC2Alph2.); format Cbsasc10 $alphasc. ; if cbsatype10=" " then do; length _cbsaname $80; _cbsaname=put(cbsa10,$cbsa40.); if index(_cbsaname,'Micropolitan') then cbsatype10='Micro'; else cbsatype10='Metro'; end; end; if not (inblks1 and inblks3) then do; _missingbdata+1; *--we allow missing data for the 2k data. There are a few in each state---; if _missingbdata le 100 then put "***Missing data for block: " inblks1= inblks3= cnty= tract= block=; else abort abend; end; *drop sldl10_ck ; drop countyck; drop _: ; label pop2k='Est Pop 2k Census'; run; proc freq data=mable14.&stab.v&t; table county; format county $county.; run; *---Write a record to end of cnvtlog.txt documenting what we just did.---; data _null_; set mable14.&stab.blks (obs=3) nobs=_nobs; file log; put / _all_ / ; file "cnvtlog.txt" mod; if _n_=1 then put "Conversion for &stab&state&t complete on &sysdate at &systime . Census blocks processed: " _nobs; stop; run; %mend doit; /* ========================begin comment==================================== %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17); %dostates(18 19 20 21 22 23 24 25 26 27 28 29 30 31); %dostates(32 33 34 35 36 37 38 39 40 41 42); %dostates(44 45 46 47 48 49 50 53 54 55 56); %dostates(51); *---We found an error in MN (the CBSA code for Fairmont Micropolitan Area) so rerunning 2-25-16---; %dostates(27) ==========================end comment====================================== */ options NOmprint; %**dostates(n=51); %let t=T; *--for test set to a value of T. For production set to null.----; %let regencocds1=1; *<=====================if specified, leaves block level sets alone but redoes cocds1 and the view---; %dostates(05) ; *--regenerating Arkansas (3-20-17) after finding problem with Hempstead co CBSA code. -; ***after this run for 05 (Ark) in T mode worked we interactively renamed the old arcocds1 set to arcocds1x and then arcocds1T to arcocds1.-; %**dostates(51) ; *--test run with hsa hrr codes added (VA only) 9/1 --;