x cd /pub/data/sf12010/Tools; %let pgm=aggsf1_mocoregns; filename pgm "&pgm..sas"; *---Aggregation of 2010 Summary File 1 complete table data sets to Missouri county-based regions. Uses custom aggregation code from Ellen Cryan at Cleveland State U. Adapted by jgb, OSEDA/MCDC running Dec 2011. This code aggregates sf12000 data to various Missouri regions, creating ph and pct data sets for: rpc - Regional Planning Commissions ded - Dept of Economic Development regions dot - Dept of Transportaion districts umx2 - UM Outreach and Extension regions. aaa - Area agency on aging regions. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Under contract with the Missouri Census Data Center . 1/12/ ---*; libname sf12010 '/pub/data/sf12010'; libname sf1 (sf12010); libname georef '/pub/data/georef' access=readonly; libname user '/SAS_temp/userb'; %let outset=moregns; %let aggbyvars=sumlev region; %let aggids=umx; title "&pgm -Aggregate 2010 SF1 Data to MO County Based Regions"; %INCLUDE SASCode(CalcMedian) ; *<---from the California SDC, Aug. 2011---; options compress=binary; *<======================IMPORTANT!!!========================; data agginsf1(compress=yes); length sumlev $3 region $3; merge georef.mocogeos(keep=county ded_region rpc umx umx2 dot aaa in=ingeos) sf1.moinventory(in=insf1 where=(sumlev='050')); by county; if not (ingeos and insf1) then do; put //'*******************PROBLEM!!!!!!!!!!!!!!!!!!!!!!: Data Missing on One of the files!!!!! '/ county= ingeos= insf1=; abort abend; end; *---Output once for each region type--; keep sumlev region _numeric_ umx; drop logrecno; sumlev='ded'; region=ded_region; output; sumlev='dot'; region=dot; output; sumlev='umx'; region=umx2; output; sumlev='rpc'; region=rpc; output; sumlev='aaa'; region=aaa; output; run; proc sort data=agginsf1; by sumlev region; run; %agg(aggin=agginsf1, aggout=aggout, aggby=&aggbyvars, idvars=&aggids, aggvars=_numeric_, means=IntPtLon IntPtLat, mweights=AreaSQMI AreaSQMI, agglvls=1,grand=no, debug=0) run; *---commented out code used in earlier run as agg parms: aggvars= pop100 hu100 p1i1--p39Ii20 h1i1--h17Ii21 IntPtLon IntPtLat AreaSQMI LandSQMI AreaLand AreaWatr, naggvars=3354, ---*; data sf1.&outset (label="Mo County-based Regions as of 2012" compress=binary); length SumLev $3 Region rpc umx ded_region dot Geocode $3 umx2 $2 Areaname $64 ; set aggout; geocode=Region; select(SumLev); when('ded') do; ded_region=region; Areaname=put(ded_region,$dedrgn.); end; when('dot') do; dot =region; Areaname=put(dot,$modot.); end; when('umx') do; umx2=region; Areaname=put(umx2,$umxname.); end; when('rpc') do; rpc=region; Areaname=put(rpc,$rpcname.); end; when('aaa') do; aaa=region; Areaname=put(aaa,$aaa.); end; otherwise do; put _lvl_= " not expected ****"; abort abend; end; end; *--select sumlev_ ---; if sumlev ne 'umx' then umx=' '; *---The following code from Ellen Cryan, Cleveland State U. with refs to CalcMedian from California SDC ---; * General macro which calculates any median using linear interpolation. ; * Macro to calculate all 30 median ages (total pop & 9 race groups by sex) using P12, P12A-P12I. Called below for custom-defined areas only. Also called by GenProf3 whenever any of the races J through O are requested) ; ARRAY P12LowBounds [23] _TEMPORARY_ (0, 5,10, 15,18, 20,21,22, 25,30,35,40, 45,50,55, 60,62, 65,67, 70,75,80,85) ; %Macro MedAge(Race) ; ARRAY P12&Race.male23 [23] P12&Race.i3 -P12&Race.i25 ; ARRAY P12&Race.feml23 [23] P12&Race.i27-P12&Race.i49 ; ARRAY P12&Race.Both23 [23] ; DO age = 1 TO 23 ; P12&Race.Both23[age] = P12&Race.male23[age] + P12&Race.feml23[age] ; END ; %CalcMedian (P13&Race.i1, 23, P12LowBounds, P12&Race.Both23, P12&Race.i1) ; %CalcMedian (P13&Race.i2, 23, P12LowBounds, P12&Race.male23, P12&Race.i2) ; %CalcMedian (P13&Race.i3, 23, P12LowBounds, P12&Race.feml23, P12&Race.i26) ; %MEnd ; ARRAY OccHU [3,0:9] H6i1-H6i8 H16Hi1 H16Ii1 /* Hisp & WhiteNH not in H6 & H14 */ H14i2-H14i9 H16Hi2 H16Ii2 /* Owners */ H14i10-H14i17 H16Hi10 H16Ii10 ; /* Renters */ %Macro AvgSize(Race,RNo) ; IF (P18&Race.i1>0) THEN P17&Race.i1=P16&Race.i1/P18&Race.i1 ; * Households ; IF (P18&Race.i1>0) THEN P17&Race.i2=P16&Race.i2/P18&Race.i1 ; * Households ; IF (P18&Race.i1>0) THEN P17&Race.i3=P16&Race.i3/P18&Race.i1 ; * Households ; IF (P35&Race.i1>0) THEN P37&Race.i1=P36&Race.i1/P35&Race.i1 ; * Families ; IF (P35&Race.i1>0) THEN P37&Race.i2=P36&Race.i2/P35&Race.i1 ; * Families ; IF (P35&Race.i1>0) THEN P37&Race.i3=P36&Race.i3/P35&Race.i1 ; * Families ; ***put 'before ' occhu[2,&RNo]= h11&race.i2= h12&race.i2=; IF (OccHU[1,&RNo]>0) THEN H12&Race.i1=H11&Race.i1/OccHU [1,&RNo] ; * all Occ HUnits ; IF (OccHU[2,&RNo]>0) THEN H12&Race.i2=(H11&Race.i2+H11&Race.i3)/OccHU [2,&RNo] ; * OwnerOcc HU ; IF (OccHU[3,&RNo]>0) THEN H12&Race.i3=H11&Race.i4/OccHU [3,&RNo] ; * RenterOcc HU ; *** put occhu[2,&RNo]= h11&race.i2= h12&race.i2=; %MEnd ; * In first call to %MedAge, Race is null (for total pop) ; %MedAge () ; %MedAge (A) ; %MedAge (B) ; %MedAge (C) ; %MedAge (D) ; %MedAge (E) ; %MedAge (F) ; %MedAge (G) ; %MedAge (H) ; %MedAge (I) ; * In first call to %AvgSize, Race is null and zero (for total pop) ; %AvgSize ( ,0) ; %AvgSize (A,1) ; %AvgSize (B,2) ; %AvgSize (C,3) ; %AvgSize (D,4) ; %AvgSize (E,5) ; %AvgSize (F,6) ; %AvgSize (G,7) ; %AvgSize (H,8) ; %AvgSize (I,9) ; *---Calculate all the age medians from the corresponding distributions. Note that we do not have explicit distrib tables for total age, but have to create the totals by summing male and female counts in each case.--; drop P12Both: P12ABoth: P12BBoth: P12CBoth: P12DBoth: P12EBoth: P12FBoth: P12GBoth: P12HBoth: P12IBoth: ; drop _: i age; run; proc sort; by sumlev geocode; run; proc print data=sf12010.&outset(keep=_character_ p1i1) ; by sumlev; id geocode areaname; var p1i1 region rpc ded_region umx umx2 aaa dot ; format areaname $20.; sum p1i1; title2 "sf12010.&outset"; run;