x cd /pub/data/stf901/Tools; %let pgm=molegdists02; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Jan 2002. Under contract with Mo Census Data Center. Aggregate/convert 1990 full stf1 data set at the (1990) census block level to create Mo (redistricted) legislative district summaries, both comple and within-county. Specfically: --> stf901.molegdists02 - new MO legistlative district totals - uses new dist geog from redistricting of 2001) sumlevs: 610, 620, 500 (Senate, House, CD) --> sftf901.molegdistcos02 - new MO leg district within county geography. sumlevs: 61c, 62c, 50c. --*; libname stf901 '/pub/data/stf901'; libname georef '/pub/data/georef' access=readonly; libname user '/SAS_temp/user'; options msglevel=i ; options compress=yes; /*<=========================Comment out===================================== *---create input set for aggregation--; data aggin; length distcode $3; merge stf901.moblks00(in=indata) georef.moblks00(keep=county tract block sldu02 sldl02 cd108 pop100 in=inref); by county tract block; if not (indata and inref) then do; if pop100=0 then delete; put / _all_; abort abend; end; sumlev='610'; distcode=sldu02; output; *--Senate--; sumlev='620'; distcode=sldl02; output; *--House--; sumlev='500'; distcode=cd108; output; *--CD--; keep sumlev distcode county _numeric_; drop pop100; run; proc datasets library=user; modify aggin; index create byvars=(sumlev distcode county); quit; %agg(aggin=aggin,aggout=aggout,aggby=sumlev distcode county, aggvars=%str(p1i1--h55i4), agglvl=2, MEANS=P17AI1 H17AI1 H18AI1 H18AI2, MWEIGHTS=P2I1 H2I1 H3I1 H3I2 , grand=0) run; ===========================End commented out================================ */ data stf901.molegdists02(label='1990 stf1 data by 2002 Legislative District Geo' drop=partflag county cnty compress=yes) stf901.molegdistcos02(label='1990 stf1 by 2002 Legislative District/Counties' compress=yes); 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 _lvl_ 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); link domedians; 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._lvl_ and last._lvl_) then do; partflag='y'; areaname=trim(areaname)||'/'||put(cnty,$mocnty.); end; else partflag='n'; output stf901.molegdistcos02; end; else do; partflag=' '; geocode=distcode; output stf901.molegdists02; end; label partflag='District Spans Counties?'; drop _lvl_ _nag_ ; return; domedians: *---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); return; drop hv1-hv20 r1-r16; *<---constant values used to re-estimate medians---; run; proc sort data=stf901.molegdists02; by sumlev geocode; run; proc sort data=stf901.molegdistcos02; by sumlev geocode; run; *-------------Print Some ID fields and do some means to verify we did not lose any data------------*; proc print data=stf901.molegdists02(obs=50 keep=_char_ p1i1 h1i1 h23bi1); title2 'Sample Data from stf901.molegdists02'; run; proc means data=stf901.molegdists02 maxdec=0 n min max sum mean; var p1i1; class sumlev; title2 'Mean Statistics Based on molegdists02'; run; proc print data=stf901.molegdistcos02(obs=50 keep=_char_ p1i1 h1i1 h23bi1); title2 'Sample Data from stf901.molegdistcos02'; run; proc means data=stf901.molegdistcos02 maxdec=0 n min max sum mean; class sumlev; var p1i1; title2 'Mean Statistics Based on molegdistcos02'; run; proc datasets library=stf901 nolist; modify molegdists02; index create geocode; modify molegdistcos02; index create geocode; index create county; quit;