x cd /pub/data/sf12010/Tools; %let pgm=agg_sf12010_uscdsldspumas2012; filename pgm "&pgm..sas"; *---Aggregation of 2010 Summary File 1 complete table data sets to new CDs and SLDs & PUMAs for entire U.S. Uses code from California SDC & from Ellen Cryan at Cleveland State U. Adapted by jgb, OSEDA/MCDC . This is an enhancement of the setup coded and run in 2011 that dealt only with Missouri data. In that setup we use the correlation list provided by J Harlan, GRC. For this run we used mable14 data. We only aggregate the P and H tables from block level - no PCT or HCT. Decided to add code to go ahead and allocate data to the new-for-2010 PUMAs that we reference as puma12. Coded 10-2-14. ---*; libname sf12010 '/pub/data/sf12010'; libname sf1 (sf12010); %**libname(corrlst,opts=); %libname(mable14); libname user '/SAS_temp/userb'; options fmtsearch=(mable14 sasctlgs work); *<---we access the $puma format code in mable14.formats catalog--; %let aggbyvars=sumlev newdist county; %let aggids=; title "&pgm -Aggregate State Level SF1 Data to US Totals With Regions and Divisions"; %INCLUDE SASCode(CalcMedian) ; *<---from the California SDC, Aug. 2011---; options compress=binary; *<======================IMPORTANT!!!========================; /* *--test run,,, %let state=10; %let stab=de; %let statenm=Delaware; */ %macro doit(state,stab); %let outset=&stab.cdsldspumas2012; /*<=========================Comment out (created in earlier run(s)===================================== *---Step 0: The sf1 dataset is not sorted by county tract and blocks so we shall create an index for that ordering---; proc datasets library=sf1 nolist; modify &stab.blocks; index create ctb=(county tract block); quit; ===========================End commented out================================ */ *----Step 1: Create, sort and filter the input data set by merging block level sf1 with the correlation list with new cds and slds---; data aggin; merge sf1.&stab.blocks(in=insf1 keep=county tract block sumlev _numeric_) mable14.&stab.v (keep=county tract block cd113 sldu12 sldl12 puma12 pop2k in=inclist); by county tract block; length newdist $5; if not (insf1 and inclist) then do; if not insf1 then _nosf1+1; else _noclist+1; _nbad+1; if _nbad=_n_ and _n_=10 then abort abend; if _nbad le 50 then put county= tract= block= insf1= inclist= ; else abort abend; drop _: ; end; *----We output 4 obs, 1 for each summary level group we want (cd, puma, senate and house)-----; sumlev='500'; newdist=cd113; output; sumlev='610'; newdist=sldu12; output; sumlev='620'; newdist=sldl12; output; sumlev='795'; newdist=puma12; output; run; proc datasets library=user nolist; modify aggin; index create s=( &aggbyvars ); quit; ***proc sort; ***by &aggbyvars; *** run; %agg(aggin=aggin, aggout=aggout, aggby=&aggbyvars, idvars=&aggids, aggvars=pop100 hu100 pop2k p1i1--p39Ii20 h1i1--h17Ii21 IntPtLon IntPtLat AreaSQMI LandSQMI AreaLand AreaWatr, means=IntPtLon IntPtLat, mweights=AreaSQMI AreaSQMI, agglvls=3,grand=no, debug=0) run; data sf1.&outset (label="US CDs, SLDs and PUMAs as of 2012" compress=binary); length SumLev $3 State $2 cd113 $2 sldl12 $3 sldu12 $3 PUMA12 $5 County $5 Areaname $96 esriid $8 ; *<----must be custom assigned.----; retain State "&state" Stab "&stab"; set aggout; *====================================Here is where sumlev, esriid and areaname need to be assigned=====; Select (_lvl_); when(1) select(SumLev); when('500') do; SumLev='510'; cd113=newdist; esriid=cd113||county; Areaname="CD "||cd113||" / "||put(county,$county.); end; when('610') do; SumLev='612'; sldu12=newdist; esriid=sldu12||county; Areaname="Senate District "||sldu12||" / "||put(county,$county.); end; when('620') do; SumLev='622'; sldl12=newdist; esriid=sldl12||county; Areaname="House District "||sldl12||" / "||put(county,$county.); end; when('795') do; delete; *--No puma-county summaries--; end; end; when(2) select(SumLev); when('500') do; cd113=newdist; esriid=state||cd113; Areaname="&statenm CD "||cd113||" (113th Congress)"; end; when('610') do; sldu12=newdist; esriid=state||sldu12; Areaname="&statenm Senate District "||sldu12||" (2012)"; end; when('620') do; sldl12=newdist; esriid=state||sldl12; Areaname="&statenm House District "||sldl12 ||" (2012)"; end; when('795') do; puma12=newdist; esriid=state||puma12; Areaname=put(esriid,$puma.); end; end; when(3) do; put Sumlev= pop100= ; delete; end; otherwise do; put _lvl_= " not expected ****"; abort abend; end; end; *--select _lvl_ ---; ***esriid=compress(geocode,'-'); *---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: ; %*---specify format code of 6.3 for all these small average-value variables---; %macro fmac(tab); format &tab.i: &tab.ai: &tab.bi: &tab.ci: &tab.di: &tab.ei: &tab.fi: &tab.gi: &tab.hi: 6.3; %mend fmac; %fmac(h12) %fmac(p13) %fmac(p17) %fmac(p36) %fmac(p37) drop _: i age; drop newdist; run; proc sort data=sf1.&outset; by sumlev esriid; run; %if &state=29 %then %do; data one; set sf1.&outset (obs=1); run; proc fsbrowse printall data=one; title2 "First Obs on sf12010.&outset"; run; %end; proc print data=sf12010.&outset(keep=_character_ p1i1); by sumlev; id cd113 sldu12 sldl12 county esriid; title2 "sf12010.&outset"; run cancel; /*<=========================Comment out===================================== proc datasets library=sf1 nolist; modify &stab.blocks; index delete ctb; quit; ===========================End commented out================================ */ %mend doit; %**dostates(10,names=1); %dostates(01 02 04 05 06 08 09 11 12 13 15,names=1,msgs=1) ; %dostates(16 17 18 19 20 21 22 23 24 25 26 27 28 29 30,msgs=1,names=1); %dostates(31 32 33 34 35 36,names=1,msgs=1); %dostates(37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56,msgs=1,names=1);