x cd /pub/data/stf903/Tools; %let pgm=molegdists02; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Aug 2002. Under contract with Mo Census Data Center. Aggregate the previously aggregated mosl090_00 dataset (1990 data aggregated to 2000 SumLev 090 geography) to create 1990 data by 2002 Missouri legisltative district geography. We use a correlation list to link these split bgs to the appropriate districts. The correlation lists used here were created by the job sbg90_legdist02.sas setup in the corrlst Tools library. We use the _wt90 versions where the afact values were based on the 1990 populations. --*; libname stf903 '/pub/data/stf903'; libname user '/SAS_temp/user'; libname corrlst '/pub/data/corrlst' access=readonly; %let sl90vars=county cousubfp placefp tract UrbanRur bg ; *---2000 defn--; options compress=yes msglevel=i; /*<=========================Comment out===================================== *--create data to be aggregated by joining the 1990 split-bg (090) level data with the 3 correlation lists, then concatenating the 3 set (interleaving, actually)---; data aggin1 unmatched1(keep=_character_ p1i1 compress=no); length State $2 DistCode $3 ; length default=5; retain SumLev '500'; merge stf903.mosl090_00(keep=&sl90vars _numeric_ in=instf3 ) corrlst.mosbg2k_cd108_wt90(in=inclist); by &sl90vars; State=substr(county,1,2); if not (instf3 and inclist) then do; if instf3 and p1i1 = 0 then delete; if not instf3 and pop90=0 then delete; _nbad +1; ***if _nbad gt 100 then abort abend; drop _nbad; if instf3 or _nbad le 25 then put / '*** ' sumlev= instf3= inclist= &sl90vars; output unmatched1; delete; end; sumlev='500'; distcode=cd108; output aggin1; *--cd--; keep sumlev distcode state county _numeric_; run; data aggin2 unmatched2(keep=_character_ p1i1 compress=no); length State $2 DistCode $3 ; length default=5; retain SumLev '620'; merge stf903.mosl090_00(keep=&sl90vars _numeric_ in=instf3 ) corrlst.mosbg2k_house02_wt90(in=inclist); ; by &sl90vars; State=substr(county,1,2); if not (instf3 and inclist) then do; if instf3 and p1i1 = 0 then delete; if not instf3 and pop90=0 then delete; _nbad +1; ***if _nbad gt 100 then abort abend; drop _nbad; if instf3 or _nbad le 25 then put / '*** ' sumlev= instf3= inclist= &sl90vars; output unmatched2; delete; end; sumlev='620'; distcode=sldl02; output aggin2; *--House--; keep sumlev distcode state county _numeric_; run; data aggin3 unmatched3(keep=_character_ p1i1 compress=no); length State $2 DistCode $3 ; length default=5; retain SumLev '610'; merge stf903.mosl090_00(keep=&sl90vars _numeric_ in=instf3 ) corrlst.mosbg2k_senate02_wt90(in=inclist) ; by &sl90vars; State=substr(county,1,2); if not (instf3 and inclist) then do; if instf3 and p1i1 = 0 then delete; if not instf3 and pop90=0 then delete; _nbad +1; ***if _nbad gt 100 then abort abend; drop _nbad; if instf3 or _nbad le 25 then put / '*** ' sumlev= instf3= inclist= &sl90vars ; output unmatched3; delete; end; sumlev='610'; distcode=sldu02; output aggin3; *--Senate--; keep sumlev distcode state county _numeric_; run; proc datasets library=user nolist; modify aggin1; index delete _all_; index create aggby=(SumLev DistCode county); modify aggin2; index delete _all_; index create aggby=(SumLev DistCode county); modify aggin3; index delete _all_; index create aggby=(SumLev DistCode county); quit; data aggin; set aggin1 aggin2 aggin3; by sumlev DistCode County; run; *----We use the module in sascode(agg903.sas) to do the aggregation, but we have to assing the global parms used by that module so it knows where things come from and go to. ----*; %let _aggin=aggin; %let _aggout=aggout; %let _aggby=sumlev distcode county; %let skipagg=0; %let _grand=0; %let _agglvl=3; %let _idvars=State; %let _facvar=afact; %include '/pub/sascode/agg903.sas'/source2; *<---include standard sas code to do the actual aggregation based on all the global parms just assigned. Includes a post step to handle medians----; *drop areaname; run; ===========================End commented out================================ */ data stf903.molegdists02(label='1990 stf3 tables by complete 2002 Legislative Districts' drop=county) stf903.molegdistcos02(label='1990 stf3 tables by 2002 Legislative Districts by County') cksums(compress=no); length sumlev $3 AreaName $40 geocode $12 House Senate $3 cd108 $2 county $5 cnty $3 distcode $3 partflag $1; set aggout; by sumlev distcode notsorted county notsorted; select (sumlev); when('610') areaname='State Senate District '||distcode; when('620') areaname='State House District ' ||distcode; when('500') areaname='108th MO Cong District ' ||substr(distcode,2,1); end; if sumlev='610' then Senate=distcode; else if sumlev='620' then House=distcode; else cd108=substr(distcode,1,2); if _lvl_=1 then do; *--its a district within county sum--; geocode=trim(distcode)||'-'||county; cnty=substr(county,3,3); substr(sumlev,3,1)='c'; *<--so, for example, House within county gets sumlev code of 62c--; *--See if it is split across counties--; if not (first.county and last.county) then do; partflag='y'; areaname=trim(areaname)||'/'||put(cnty,$mocnty.); end; else partflag='n'; output stf903.molegdistcos02; end; else if _lvl_=2 then do; partflag=' '; geocode=distcode; output stf903.molegdists02; end; else if _lvl_=3 and sumlev='500' then output cksums; label partflag='District Spans Counties?'; drop _lvl_ _nag_ ; run; *---check step to see if total pops for each legtype sum to state total pop--; proc means data=stf903.molegdists02 n sum; var p1i1; class sumlev; run; proc means data=stf903.molegdistcos02 n sum; var p1i1; class sumlev; run;