x cd /pub/data/mable09/Tools; %let pgm=genmable2k_09; filename pgm "&pgm..sas"; ***NOTE: This really should be in mable09/Tools for some reason we decided to put it here*** ; *--Generate the revised edition of mable2k data base for 2009 and beyond. Here we: 1. Merge the XXblks, XXblks2, XXblks2a and XXsldblks datasets, creating XXblks07 . 2. Create new XXcocds2 datasets with various county-based codes. These replace the old XXcocds2 datasets and have new variables beale03, ui03 (Urban influence codes) - and the county-estimates-based PopGrowth Factor . 3. For New England states only create XXblks07a with necta-related codes. 4. For Missouri only have moblks07 include nces and dese school district codes, updated for 2005 from GRC. 1 code instead of 3. 5. Create the XXv3 SAS views that merge these datasets together to make it look like all the codes are at the block level. John Blodgett, Mar, 2007 Edited and rerun July, 2010 to fix necta, nectadiv problem and updating popest weight to 2009. --*; /* Update History Rev. 3/09 to upgrade CBSA and related codes and latest pop estimate (to 2008). We call it 07 but its really more current than that. We modify the doit macro so that we specify that only want to recreate the cocds02 data sets. 10/09 run to upgrade the CBSA codes again using the Nov 2008 definitions. Special run 2-21-15 to fix cd108 variable for Parke county, Indiana (18121). */ %include '/pub/sas/autoexec.sas'; %let popestyr=09; *<----controls what uscom data set we access and what popjlXX estimate we use---------; %let yy=09; %let mableyy=mable09; *<===; %let mablepath=%str(/pub/data/mable09); libname mable2k "&mablepath" access=readonly; libname &mableyy "/pub/data/mable&yy"; *<-------------This is where we write-------------; libname georef '/pub/data/georef' ; *** access=readonly; libname popests '/pub/data/popests' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; title "&pgm.: Generate the Vingtage 2006 Mable Database"; %let debug=0; options mprint; %macro doit(state,stab,cocds2only=0); %*---Create the cocds2 dataset with the 06 cbsa related codes, the pop-gorwth factor based on the ratio of the 06 estimate and the census count, and the new uic and beale03 codes. --; %*---We add the cocds2only parm to allow us to specify whether we want to run a full update or just on the cocd2 data set. 3-27-09--; %if &state=02 %then %do; %*---We need a different set of codes for Alaska where they split one of the county equivs in 2008 estimate year--; data georef.akbeale03; set georef.usbeale03(where=(state='02')); if county='02232' then do; county='02105'; output; county='02230'; output; end; else output; run; proc sort; by county; run; data georef.ak_erscodes; set georef.us_erscodes(where=(state='02')); if county='02232' then do; county='02105'; output; county='02230'; output; end; else output; run; proc sort; by county; run; %let us_ak=ak; %end; %else %let us_ak=us; data &mableyy..&stab.cocds2(label="More county-based codes including 20&popestyr cbsas, beale03 and ui_code" index=(county)); merge popests.uscom&popestyr (keep=sumlev state cnty county cbsa metrodiv cbsayr cbsatype popcen2k pop00C popjl&popestyr in=inests) georef.&us_ak.beale03(keep=state county beale03 beale93 in=inbeale) georef.&us_ak._erscodes(keep=state county ui_code in=iners) %if &state=29 %then %do; georef.mocogeos(keep=state county DED_Region rpc umx2 dot aaa rename=(ded_region=ded umx2=uoe) in=inmogeos) %end; ; by state county; where state="&state"; %if &state=02 %then %str( where also county ne '02232'; ); if sumlev='040' then delete; if not (inests and inbeale and iners) then do; _nerr+1; if _nerr le 20 then put / "***Data missing for this county: " county $5. +1 county= inests= inbeale= iners= ; else abort abend; end; if cbsa='99999' then csa=' '; else if cbsa ne '99999' then if cbsa ne lag(cbsa) then do; set georef.cbsas(keep=cbsa csa) key=cbsa; _savecsa=csa; retain _savecsa; end; else csa=_savecsa; if popcen2k <= 0 then popcen2k=pop00c; *--for counties like Broomfield, CO that did not exist in 2000 census--; PopGrowthFactor=popjl&popestyr /popcen2k; format PopGrowthFactor 6.3; label popgrowthfactor="Pop Growth Factor County-based 2k to 7/&popestyr"; drop _: sumlev popcen2k pop00c cnty; run; %if &debug %then %do; proc print data=&mableyy..&stab.cocds2 (obs=200); title2 "&syslast - First 200 Obs"; run; %end; %if &cocds2only %then %goto define_view; %*<=============================NOTE====================================; *----Update the blocks dataset. We combine 4 (or more) different block datasets to get the new blocks set---; %if %index(09 23 25 33 44 50,&state) %then %do; %*--we need NECTA and NECTADIV codes in New England only--; proc sort data=mable2k.&stab.blks(keep=county tract block cousubfp) out=&stab.blks; by county cousubfp; run; data &stab.blks2; merge &stab.blks(in=inblks) georef.nectamcds(keep=state county MCD Necta nectadiv rename=(MCD=cousubfp) where=(state="&state") in=inref); by county cousubfp; if not inblks then do; put '***error merging blocks with georef.nectamcds*** ' _all_; _nbad+1; if _nbad ge 20 then abort abend; end; if inref; *--It is OK to have a block that is not in the necta set. That just means it is not in any NECTA---; drop _: state ; run; proc sort out=&mableyy..&stab.blksnecta; by county tract block; run; %end; data &mableyy..&stab.blks07; merge mable2k.&stab.blks(in=inblks1) mable2k.&stab.blks2(in=inblks2 keep=county tract block ua ur ur90 puma5) mable2k.&stab.blks2a(in=inblks2a keep=county tract block ua ur puma5 ur00cor ua00cor ua90 ua90red ur90 ur90red cd108) mable2k.&stab.sldblks(in=insld) %if &state=29 %then %do; corrlst.mobl2schl05(in=inschls drop=state) %end; %if %index(09 23 25 33 44 50,&state) %then %do; %*--we need NECTA and NECTADIV codes in New England only--; &mableyy..&stab.blksnecta(in=innecta) %end; ; by county tract block; %if %index(09 23 25 33 44 50,&state)=0 %then %do; %*--we need NECTA and NECTADIV codes "declared" outside New England only--; length necta $5 nectadiv $5; %end; %*----add conditional custom code here for Missouri-----------------------------------------------*; %if &state=29 %then %do; *** length desecode $6 ncescode $5; label desecode='6-digit DESE dist code circa 2005' ncescode='5-digit NCES schl dist code circa 2005' disttype='MO schl dist type: U or E'; %end; if not (inblks1 and inblks2 and inblks2a and insld) then do; put "*************Error: Missing a block obs on one of the 4 blks datasets****"; abort 500; *<=================TEMPORARY!!!!!!!==============; %if &state=29 %then %do; if not inschls then do; put 'No school codes for this block: ' county= tract= block=; _nbad+1; if _nbad gt 1000 then abort abend; drop _nbad; end; %end; end; run; %define_view: data &mableyy..&stab.v3(label="All variables for &stab rev. to 08")/view=&mableyy..&stab.v3; *---this is the defn of the view that combines all the real datasets---; set &mableyy..&stab.blks07; by county; county02=county; *---recode here is for the 2 cases in Virginia and Colorado, where county defns have changed since 2000--; if county='51560' then county02='51005'; else if state='08' and placefp='09280' then county02='08014'; else if state='02' and county='02232' then do; *---new for the 2009 version. Change was made between the 07 and 08 popests years--; if placefp='70760' then county02='02230'; else county02='02105'; end; if first.county then do; %*---The conditional keep= spec for MO drops some extra variables that we earlier added to the mococds1 dataset. We now get these variables from the new mococds2 dataset, which is modified to grab the extra MO variables from georef.mocogeos (see above)----; set mable2k.&stab.cocds1(%if &state=29 %then %str( keep=state--cohus2k ); rename=(county=countyck)); %if &state ne 08 and &state ne 51 and &state ne 02 %then %do; set &mableyy..&stab.cocds2(rename=(county=countyck2)); %end; end; %if &state=08 or &state=51 or &state=02 %then %do; _save=county; drop _save; county=county02; %*--do keyed read on the cocds2 set using county02 as key--; if county ne lag(county) then set &mableyy..&stab.cocds2 key=county; if _iorc_ then do; put "*****ERROR doing keyed read of &stab.cocds2 dataset for county " county $5. +1 county $county. ; _error_=1; end; county=_save; countyck2=county; %end; %*---code to customize defn of cbsa-related codes for Sullivan city portion of Crawford co, MO.--; %if &state=29 %then %do; if county='29055' then if placefp='71440' then do; cbsa='41180'; cbsatype='Metro'; cbsayear='2005'; end; else do; cbsa=' '; cbsatype=' '; cbsayear=' '; end; %end; if cbsa='99999' then cbsa=' '; if county ne countyck then do; put "*************Error: county code on &stab.cocds1 dataset does not match that on the blks datasets****"; abort 600; end; if county ne countyck2 then do; put "*************Error: county code on &stab.cocds2 dataset does not match that on the blks datasets****"; abort 601; end; drop countyck countyck2; format county $5.; run; %if &debug %then %do; proc print data=&mableyy..&stab.v3 (obs=40); by state stab cnty; id tract block; title2 "Some Observations from &mableyy..&stab.v3 (View with revised geocodes)"; run; proc means maxdec=0 n sum data=&mableyy..&stab.v3; *---This step tests the view because it looks at entire set-; class state county cd109 sldl02 sldu02 cd109 cbsa csa beale03 ui_code / missing; var pop2k ; types state county cd109 sldu02 cbsa csa beale03 ui_code ; title2 'Some Proc Means summaries for various geographies'; run; %end; %mend doit; options NOmprint; %***dostates(01 09,msgs=1); /*<=========================Comment out===================================== %dostates(02 04 05 06 08 10 11 12 13 15 16 17,msgs=1); %dostates(18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36,msgs=1); %dostates(23 37 38 39 40 41 42); %dostates(44 45 46 47 48 49 50 51 53 54 55 56); *----custom run for Alaska only to try and get around problems caused by splitting of a Census Area (county equivalent) in 2008 estimate year. redefine the Alaska blocks. ----; %**doit(02,ak) *---Special run to fix cd108 variable for Parke County, IN-----*; data mable09.inblks07edited; set mable09.inblks07; if county='18121' and cd108=' ' then cd108='08'; run; proc freq data=mable09.inblks07edited(where=(county='18121')); table county*cd108; run; ==========================end comment====================================== */ %dostates(02 08 51);