x cd /pub/data/popests/Tools; %let pgm=aggpopests_moschls05; filename pgm "&pgm..sas"; /*----------------------------------------------------------------------------------------------------------------- This code estimates the pop and hu countis for MO school districts for 2005. We use a recent correlation list to relate BGs to SDs and we use the EasiData pop estimates for 2005 by bg. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Revision History: 01.29.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 School Districts"; options mstored sasmstore=library; /* =======================Begin comment================ data _null_; retain word "%easipwd"; put _all_; run cancel; *--generate the bg to school district correlation list using the block to school district list and a utility--; data corrwtin; length ncescode $5; merge corrlst.mobl2schl05(in=in1 rename=(ncescode=_nces)) 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; ncescode=_nces; _nflags+ flag; if last then put _nflags=; drop _: ; if pop2k=0 then delete; run; proc sort data=corrwtin; by county tract bg ncescode; run; %corrwt(setin=corrwtin,setout=user.mobg2schl05, g1=county tract bg, g2=county ncescode, wtvar=pop2k,keepwt=1, idvars=desecode DistType, 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.mobg2schl05(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; ncescode='99999'; desecode='999999'; disttype='U'; link output ; end; else do; _nbad+1; put _nbad= county= tract= bg=; delete; end; end; else link output; return; output: if ncescode=' ' then do; ncescode='99999'; desecode='999999'; disttype='U'; end; output aggin; delete; drop _: ; run; proc print data=aggin(obs=50); by county; title2 "aggin"; run; proc sort data=aggin; by disttype ncescode county ; run; %agg(setin=aggin, setout=aggout, aggby=disttype ncescode county, agglvl=2, facvar=afact, aggvars=popest05 popproj10, debug=0) ; run; data moschls05; set aggout; select(_lvl_); when(1) do; if disttype='U' then SumLev='su2'; else SumLev='se2'; geocode=ncescode||'-'||county; end; when(2) do; if disttype='U' then SumLev='sdu'; else SumLev='sde'; geocode=ncescode; end; end; *--select stmt--; popest05=round(popest05); popproj10=round(popproj10); drop afact; drop _lvl_ _nag_; run; proc sort data=moschls05; by geocode sumlev; run; proc print data=moschls05(obs=40); title2 'moschls05'; by geocode; id geocode; run; ======================End comment================== */ *----Access the sf32000x.moschlcos dataset to get geographic ids for merging as well as HU estimates----; data geocodes; set sf32000x.moschls(keep=_character_ totpop100 tothhs avghhsize gqpop) sf32000x.moschlcos(keep=_character_ totpop100 tothhs avghhsize gqpop where=(ncescode ne '99999')); by sumlev geocode; *---some things that have change or that were mistakes---; if geocode='04890-29073' then do; *--this was a mistake. In Gasconade Co it was referring Scott Tco R IV which is not close. Digits in nces code were switched - should have been Osage Co R1. We fix it. --; geocode='08490-29073'; ncescode='08490'; desedist='076081'; substr(esriid,1,5)=ncescode; substr(grcid,1,5)=ncescode; end; if ncescode in ('26260','32440') then do; *--Revere and Wyakonda went from Unifired to Elementary districts---; if county=' ' then SumLev='sde'; else SumLev='se2'; end; run; proc sort; by geocode sumlev; run; data popests.moschls05(label='MO School Districts and within-county w 2005 ests + 2010 proj pop') problems; merge moschls05(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.moschls05; 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 School Correlation List with 2K Schools Data File'; run; proc tabulate data=popests.moschls05; title2 'Tabulate Summaries Using se2 and su2 Data'; where sumlev in ('se2','su2'); class sumlev; var pop2k popest05 hhs2k hhest05 ; table pop2k popest05 hhs2k hhest05, (all sumlev)*sum*f=comma9. ; run; proc tabulate data=popests.moschls05; title2 'Tabulate Summaries Using sde and sdu Data'; where sumlev in ('sde','sdu'); 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_moschls&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.moschls&yr (where=(sumlev in ('sde','sdu'))); title "Population Estimates And Projections for Missouri School 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_moschls&yr..sas from Data in popests.moschls&yr"; id geocode; var areaname pop2k popest&yr hhs2k hhest05 popproj10 hhproj10 ; sum _numeric_; run; ods html close;