x cd /pub/data/stf901/Tools; %let pgm=create_moblks00; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Aug 2001. Under contract with Mo Census Data Center. Aggregate/convert 1990 full stf1 data set at the (1990) census block level to create moblks00 with the same tables but aggregated to 2000 census block geography. We also create summaries at the 2000 block group and census tract levels. The data sets generated here involve converting from 1990 census geography to 2000 geography using a 1990 to 2000 Missouri block correlation list as created in cnvt.bl90_bl2k.sas in corrlst/Tools. --*; libname stf901 '/pub/data/stf901'; libname user '/SAS_temp/user'; libname corrlst '/pub/data/corrlst' access=readonly; libname sf12000 '/pub/data/census_2000/sf12000' access=readonly; /*<=========================Comment out===================================== proc sort data=stf901.moblks force; by county tract blk; *<---it was sorted by mcd and place between county & tract-; run; proc datasets library=stf901; modify moblks; index create county; quit; ===========================End commented out================================ */ *--create a sorted extract from the sf1.mogeos data set that will be merged with the 90 aggregates to provide more 2000 geographic info to these 1990 data summaries.---; data mogeos; length geocode $18; set sf12000.mogeos( where=(sumlev in ('040','050','101','150','140') and geocomp='00') keep=geo_id geocomp geocode county tract bg block sumlev cousubfp placefp msacmsa cd106 sldu sldl vtd zcta5 pop100 hu100 intptlat intptlon sduni sdelm taz landsqmi areasqmi placedc placesc); *--fill the NA codes with 9s so they match up with the aggout set where we used fillby=HIGH--; *--Whoops - agg does not "fill" with hex FFs, it just assigns a single FF followed by trailing blanks. --; retain _high 'FF'x; drop _high; if sumlev ne '101' then do; block=_high; if sumlev lt '150' then bg=_high; if sumlev lt '140' then tract=_high; if sumlev = '040' then county=_high; end; rename pop100=pop2000 hu100=hu2000; label pop100='Total Pop from SF1 2000' hu100='Total Hsng Units from SF1 2000'; run; proc sort data=mogeos; by county tract bg block; run; /*<=========================Comment out===================================== *--create data to be aggregated by joining the 1990 stf1 block level data with the blk correlation list-; data aggin(drop=pop90a notin compress=yes) nomatch(keep=county tract90 block90 pop90a p1i1 h1i1 notin); *--match the stf1 90 blocks with the corr list to attach the 2000 geocodes, i.e. tract and block; length notin $7 ; merge stf901.moblks(in=instf1 rename=(tract=tract90 blk=block90) keep=county tract blk _numeric_) corrlst.mobl902k(in=inclist where=(substr(block90,2,2) ne '99')); by county tract90 block90; if not (inclist and instf1) then do; if inclist then notin='STF1 '; else notin='CORRLST'; if pop90a then output nomatch; *--if it is in clist and there is no pop to be allocated forget it-; return; end; length default=5; output aggin; label tract='tract 2000' block='block 2000'; keep notin pop90a county tract90 block90 tract bg block afact p1i1 -- h55i4 ; run; proc sort data=aggin; by county tract block afact; run CANCEL; *<=====SORT FAILED!!! Use index instead===; proc datasets ddname=user; modify aggin; index delete hier; index create hier=(county tract bg block afact); quit; ===========================End commented out================================ */ options msglevel=n ; options compress=yes; %agg(aggin=aggin,aggout=aggout,aggby=county tract bg block,agglvls=4,grand=1,fillby=HIGH, aggvars=p1i1--h55i4, MEANS=P17AI1 H17AI1 H18AI1 H18AI2, MWEIGHTS=P2I1 H2I1 H3I1 H3I2 , facvar=afact) ; run; data stf901.moblks00(label='1990 stf1 extract by 2000 census blks' compress=yes sortedby=county tract block) stf901.mobgs00(label='1990 stf1 extract by 2000 census block grps' drop=block afact nagg compress=yes sortedby=county tract bg) stf901.motrs00(label='1990 stf1 extract by 2000 census tracts' drop=bg block afact nagg compress=yes sortedby=county tract) stf901.mocntyck(label='1990 stf1 extract check sums: st and cnty' compress=no drop=tract bg block afact nagg); length sumlev $3 county $5 tract $7 bg $1 block $5 geocode $18 areaname $16; merge mogeos(in=ingeos) aggout(in=inagg) ; by county tract bg block; if not inagg and sumlev='101' and pop2000=0 then delete; if not ingeos then do; _nbad+1; drop _nbad; if _nbad le 25 then put "**Not matched on sf12000 geos file: " county= tract= bg= block=; if _nbad ge 25 then do; put '****step aborting*****'; abort abend; end; end; array counts(*) p1i1 -- h55i4; if inagg then do _i=1 to dim(counts); counts(_i)=round(counts(_i),.1); *--round all counts to 1 decimal place--; end; drop _i; *---code taken from the sascode(aggstf1.sas) module. Estimate percentiles using median macro--; RETAIN HV1 15000 HV2 HV3 HV4 HV5 HV6 HV7 HV8 5000 HV9 10000 HV10 15000 HV11 HV12 HV13 HV14 HV15 25000 HV16 HV17 50000 HV18 HV19 50000 HV20 200000 R1 100 R2-R14 50 R15 250 R16 500; ARRAY HVALUE HV1-HV20; *<--MEASURES OF THE "WIDTHS" OF H23 CELLS; ARRAY RENTS R1-R16; *<--MEASURES OF THE "WIDTHS" OF H32 CELLS; ARRAY NVALUE H23I1-H23I20; ARRAY NRENTS H32I1-H32I16; %MEDIAN(INTSIZE=HVALUE,INTVALS=NVALUE,Q1=H23AI1,MDN=H23BI1,Q3=H23CI1) %MEDIAN(INTSIZE=RENTS,INTVALS=NRENTS,Q1=H32AI1,MDN=H32BI1,Q3=H32CI1, SAMESTEP=1) *--ROUND ALL VALUES TO NEAREST DOLLAR--*; H23AI1=ROUND(H23AI1); H23BI1=ROUND(H23BI1); H23CI1=ROUND(H23CI1); H32AI1=ROUND(H32AI1); H32BI1=ROUND(H32BI1); H32CI1=ROUND(H32CI1); P17AI1=ROUND(P17AI1,.01); H17AI1=ROUND(H17AI1,.01); H18AI1=ROUND(H18AI1,.01); H18AI2=ROUND(H18AI2,.01); drop hv1-hv20 r1-r16; *<---constant values used to re-estimate medians---; if not inagg then select(sumlev); when('101') _lvl_=1; when('150') _lvl_=2; when ('140') _lvl_=3; end; select (_lvl_); when(1) do; sumlev='101'; geocode=%concatd(county,tract,block); areaname='Block '||block; output stf901.moblks00; end; when(2) do; sumlev='150'; geocode=%concatd(county,tract,bg); block=' '; *--remove the HIGH fill-; areaname='Block Grp '||bg; output stf901.mobgs00; end; when(3) do; sumlev='140'; geocode=%concatd(county,tract); bg=' '; block=' '; areaname='Tract '||tract; output stf901.motrs00; end; when(4) do; sumlev='050'; geocode=county; areaname=put(county,$county.); tract=' '; bg=' '; block=' '; output stf901.mocntyck; end; when(99) do; sumlev='040'; geocode='29'; areaname='Missouri'; tract=' '; bg=' '; block=' '; county=' '; output stf901.mocntyck; end; otherwise do; if inagg then do; put /'***Unexpected value for _lvl_ code: ' _lvl_= / _all_; delete; end; end; end; *--select--; rename _nag_=nagg; label _nag_='# of block or blk parts aggregated' afact='Largest allocation factor' sumlev='Geo Summary Level'; drop _lvl_; run; *----verify that populations add up-------------*; *---This step ran successfully from DM and verified pop counts, 8-6-01 14:50 ---; data popcks; set stf901.moblks00(keep=sumlev county pop2000 p1i1) stf901.mobgs00(keep=sumlev county pop2000 p1i1) stf901.motrs00(keep=sumlev county pop2000 p1i1) stf901.mocntyck(keep=sumlev county pop2000 p1i1); run; proc tabulate data=popcks; class sumlev county; var pop2000 p1i1; table sumlev, pop2000 *sum*f=comma12.; title2 'Summary Checks to Verify Pop Totals on Aggregated Data Sets'; run;