x cd /pub/data/popests/Tools; %let pgm=aggpopests_mosldu05; filename pgm "&pgm..sas"; /*----------------------------------------------------------------------------------------------------------------- This code estimates the pop and hu countis for MO state senate districts for 2005. We use a recent correlation list to relate BGs to slds (state leg districts) and we use the EasiData pop estimates for 2005 by bg. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Revision History: 061.25.07 Coding begins. ------------------------------------------------------------------------------------------------------*/ options ls=132 ps=60 ; %let yr=05; *---we aggregate the estimates data in popests.mocom&yr to create popests.mocomregns&yr --; libname user '/SAS_temp/user'; libname popests '/pub/data/popests'; libname easidata '/pub/data/popests/easidata' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; %libname(mable2k); title "&pgm : Aggregate 1-1-05 Pop Estimates to State Senate Districts"; options mstored sasmstore=library; data _null_; retain word "%easipwd"; put _all_; run cancel; /* =======================Begin comment================ ======================End comment================== */ *--generate the bg to senate district correlation list using the block to senate district list and a utility--; data corrwtin; length sldu02 $3; merge corrlst.mobl2senate(in=in1 ) mable2k.moblks(keep=county tract block BG pop2k hus2k in=in2) end=last; by county tract block; length Flag 3; if not (in1 and in2) then Flag=1; else Flag=0; _nflags+ flag; if last then put _nflags=; drop _: ; if pop2k=0 then delete; sldu02=sldu; drop sldu; run; proc sort data=corrwtin; by county tract bg sldu02; run; %corrwt(setin=corrwtin,setout=user.mobg2sldu02, g1=county tract bg, g2=county sldu02, wtvar=pop2k,keepwt=1, idvars=, listn=0); *---Merge the correlation list with the easidata estimates--; data aggin nodata; merge easidata.usbgs05_10(password=%easipwd in=in1 where=(state='29') keep=state county tract bg pop:) user.mobg2sldu02(in=in2 drop=pop2k); by county tract bg; if not (in1 and in2) and (popest05 ne 0) then do; if not in2 then output nodata; else if in1 then do; sldu02='999'; link output ; end; else do; _nbad+1; put _nbad= county= tract= bg=; delete; end; end; else link output; return; output: if sldu02=' ' then do; sldu02='999'; end; output aggin; delete; drop _: ; run; proc print data=aggin(obs=50); by county; title2 "aggin"; run; proc sort data=aggin; by sldu02 county ; run; %agg(setin=aggin, setout=aggout, aggby= sldu02 county, agglvl=2, facvar=afact, aggvars=popest05 popproj10, debug=0) ; run; data mosldu05; set aggout; select(_lvl_); when(1) do; SumLev='61c'; geocode=sldu02||'-'||county; end; when(2) do; SumLev='610'; geocode=sldu02; end; end; *--select stmt--; popest05=round(popest05); popproj10=round(popproj10); drop afact; drop _lvl_ _nag_; run; proc sort data=mosldu05; by geocode sumlev; run; proc print data=mosldu05(obs=40); title2 'mosldu05'; by geocode; id geocode; run; *----Access the sf32000x.mosldcos dataset to get geographic ids for merging as well as HU estimates----; data geocodes; set sf32000x.moslds(keep=_character_ totpop100 tothhs avghhsize gqpop) sf32000x.mosldcos(keep=_character_ totpop100 tothhs avghhsize gqpop); by sumlev geocode; where sumlev=:'61'; **--filter out the 620 and 62c House summaries--; *---some things that have change or that were mistakes---; run; proc sort; by geocode sumlev; run; data popests.mosldu05(label='MO Senate Districts and within-county w 2005 ests + 2010 proj pop') problems; merge mosldu05(in=in1) geocodes(in=ingeos); by geocode sumlev; _hhpop05=popest05-gqpop; hhest05=round (_hhpop05/avghhsize); _hhpop10=popproj10-gqpop; hhproj10=round (_hhpop10/avghhsize); if in1=0 and totpop100=0 then delete; if not (in1 and ingeos) then output problems; else output popests.mosldu05; label hhest05="Est Households 2005" hhproj10="Projected Households 2010"; rename totpop100=pop2k tothhs=hhs2k; label totpop100='Pop 2k (100%)' tothhs="Hshlds 2k (sample est)"; drop _: ; run; options ls=132 nodate; proc print data=problems(drop=esriid grcid popproj10 hhproj10 hhest05); title2 'Problems (with Merging BG to State Senate Correlation List with 2K Senate Data File'; run; proc tabulate data=popests.mosldu05; title2 'Tabulate Summaries Using sldu05 Data'; where sumlev ='610'; class sumlev; var pop2k popest05 hhs2k hhest05 ; table pop2k popest05 hhs2k hhest05, (all sumlev)*sum*f=comma9. ; run; proc tabulate data=popests.mosldu05; title2 'Tabulate Summaries Using sde and sdu Data'; where sumlev ='61c'; class sumlev; var pop2k popest05 hhs2k hhest05 ; table pop2k popest05 hhs2k hhest05, (all sumlev)*sum*f=comma9. ; run; %let yr=05; ods html file="../Reports/popests_mosldu&yr..html" style=sasweb; ods listing close; *---Run a test step to see if everything sums up to state total pop---; proc print label data=popests.mosldu&yr (where=(sumlev ='610')); title "Population Estimates And Projections for Missouri State Senate Districts, as of Jan 1, 20&yr"; title2 "Aggregated from EasiData BG Estimates with HH Estimates Based on Avg HH Size from 2K Census"; footnote .h=1 "Produced by setup in popests/Tools/aggpopests_mosldu&yr..sas from Data in popests.mosldu&yr"; id geocode; var areaname pop2k popest&yr hhs2k hhest05 popproj10 hhproj10 ; sum _numeric_; run; ods html close;