x cd /pub/data/mable2k/Tools; %let pgm=tiger_codes108; filename pgm "&pgm..sas"; *--Read the tiger "108th CD" files to get new 108th CD + revised UA geocodes for mable2k. For each state we create a new mable2k.&stab.blks2a dataset with the new variables. This set will replace the &stab.blks2 dataset when we update to the new database. John Blodgett, April/July, 2003. Running for all states, Aug 27, 2003. --*; libname mable2k "/pub/data/mable2k"; libname user "/SAS_temp/userb"; filename cnvtlog '/pub/data/mable2k/tigercodes108.cnvtlog'; *<--messages written here documenting conversion--; %include 'spblk108.sas'/source2; *<---proc format code to define the $spblk. format code that looks up split blks and assigns them a cd108 code--; run; %let state=29; %let stab=mo; %let state=18; %let stab=in; *<---do test run on Indiana county---; %macro doit(fipco,cnytname); %*--Macro to process a single county. We shall then use the docos utility macro to do the entire state--; filename Ain clear; ***filename Cin clear; filename Sin clear; filename Ain pipe "unzip -pa /pub/data/tiger108/tgr&fipco..zip TGR&fipco..RTA"; *filename Cin pipe "unzip -pa /pub/data/tiger108/tgr&fipco..zip TGR&fipco..RTC"; filename Sin pipe "unzip -pa /pub/data/tiger108/tgr&fipco..zip TGR&fipco..RTS"; %*--set spbflag flag to id the few counties in the US where a cd108 splits blocks. We have to select the appropriate block in these cases per the list of which-block-to-use at http://www.census.gov/geo/www/tiger/tgrcd108/spblk108.txt . ; %let spltcos=18003 18029 18039 18067 18081 18097 21011 21111 21209 42003 42011 42041 42045 42051 42069 42079; %let spltcos=&spltcos. 42091 42101 42125 42129 55015 55105; %if %index(&spltcos,&fipco) %then %let spbflag=1; %else %let spbflag=0; %if &spbflag %then %put ***Program will look for split blocks while processing county &fipco *****; data acodes; infile Ain lrecl=98; input rt $1. cenid $11-15 polyid 16-25 cd108 $53-54 puma5 $60-64 ua90 $86-89 ; ****ua $81-85; if rt ne 'A' then do; put 'Record type is not A! --- aborting...' / _all_; list; stop ; end; if _error_ then do; file log; put "***Abending due to error condition trying to read the RTA file for state &stab, county &fipco" /_all_; list; file cnvtlog mod; put "***Abending due to error condition trying to read the RTA file for state &stab, county &fipco"; abort abend; end; drop rt; run; proc sort; by cenid polyid; run; data scodes; infile Sin lrecl=120; *---Only read what we need-----*; input rt $1. cenid $11-15 polyid 16-25 county $47-51 tractin $72-77 block $78-81 ur00cor $82 ua00cor $103-107 ua90red $108-112 ur90red $113 ; * ur $119 ur90 $120; if rt ne 'S' then do; put 'Record type is not S! --- aborting...' / _all_; list; stop ; end; length tract $7; tract=substr(tractin,1,4)||"."||substr(tractin,5,2); ***if placefp2=' ' then placefp2='99999'; drop tractin rt; label ur00cor='Urban Rural Indicator 2000, Corrected' ua00cor='Urban Area Code 2000, corrected' ua90red='Urban Area Code, 1990 redfined on Census 2000 Criteria' ur90red='Urban/Rural Indicator, 1990 redefined on Census 2000 Criteria'; run; proc sort data=scodes; by cenid polyid; run; data sa; merge scodes acodes; by cenid polyid; %if &spbflag %then %do; %*---Add code here 7-24-03 to check for those census blocks that are split by cd108s. The Bureau posted a list indicating what blocks these are and specifying which of the multiple cd108 codes assigned to that block would be used for the sake of allocating census data. We use that code in mable. The work was done by creating the $spblk format code, which happens with included code at the top of this setup. There are fewer than 100 blocks nationwide and it only happens in 4 states. This check only occurs for counties where it is reported to occur.-; length _arg $15 _cd $2; drop _arg _cd; _arg=county||trim(compress(tract,'.'))||block; _cd=put(_arg,$spblk.); if _cd ne ' ' and _cd ne cd108 then delete; *--logic: _cd not blank means it occurs in the format code so it IS a split block. Once we know that it is split then if we see that the current cd108 code is not the one that is to be used then we delete the observation. Note that the block should (must!) occur elsewhere on the set with the "preferred" cd108 value.---; %end; run; proc sort data=sa nodupkeys; by county tract block cd108 puma5 ur00cor ua00cor ; run; %if %sysfunc(exist(user.&stab.blks108)) %then %let force=%str(); %else %let force=force; proc append data=sa base=user.&stab.blks108 &force ; run; %mend doit; %*docos(state=29,msgs=1); %macro doit_st(state,stab); %let n2=0; %reset(user.&stab.blks108); *<--for start-overs this will erase any data in this set--; %*reset(mable2k.&stab.cnames); *<---ditto-; %*---docos invokes doit for each county in the state, creating user.&stab.blks108-----; %docos(state=&state,msgs=1) ; *----Apply the new dataset as an update to the old &stab.blks2 dataset----; data mable2k.&stab.blks2a(label='With tiger108 updates applied'); update mable2k.&stab.blks2(in=inblks2) user.&stab.blks108(in=in108) end=last; by county tract block; if inblks2; if not in108 then _no108+1; drop _no108; if last then if _no108 then call symput('no108',left(trim(put(_no108,5.)))); else call symput('no108','0'); run; data _null_; if 0 then set mable2k.&stab.blks2 nobs=n1; if 0 then set mable2k.&stab.blks2a nobs=n2; file cnvtlog mod; call symput('n2',put(n2,7.)); now=time(); put now datetime. " &state&stab tiger108 processing complete. &stab.blks2a has " n2 " observations." ; retain no108 &no108; if no108 then put no108 comma5. +1 "observations on &stab.blks2 not matched on the &stab.blks108 set *****"; file stdout; put now datetime. " &state&stab tiger108 processing complete. &stab.blks2 has " n2 " observations." ; if no108 then put no108 comma5. +1 "observations on &stab.blks2 not matched on the &stab.blks108 set *****"; if n1 ne n2 then put "***Block Counts do not match for &stab . &stab.blks2a has " n1 "observations."; stop; run; %if &n2=0 %then %do; data _null_; file cnvtlog mod; put "***aborting convert run because no blocks detected for mable2k.&stab.blks2a"; abort abend; run; %end; %mend doit_st; options mprint; %*doit(18003,Allen) ; /*<=========================Comment out===================================== %dostates(29,mac=doit_st,msgs=1); %dostates(10,mac=doit_st,msgs=1); %dostates(01 02 04 05 ,mac=doit_st,msgs=1); %dostates(06 08 09 11 12 13 15 16 17 18 19 20,mac=doit_st,msgs=1); %dostates(21,mac=doit_st,msgs=1); ===========================End commented out================================ */ %dostates(22 23,mac=doit_st,msgs=1); %dostates(24 25 26 27 28 30 31 32 33 34 35 36 37 38 39 40,mac=doit_st,msgs=1); %dostates(41 42 44 45 46 47 48 49 50 51 53 54 55 56,mac=doit_st,msgs=1);