x cd /pub/data/sf12010/Tools; %let pgm=agguas2010; filename pgm "&pgm..sas"; *---Aggregate 2010 SF1 data sets to new Uranized Areas and to UR categories for state of MO using equivalency file created using files from Bureau processed by GRC to get the block/UA equivalency. JGB, OSEDA. ---*; libname sf12010 '/pub/data/sf12010'; libname georef '/pub/data/georef' access=readonly; libname sf1 (sf12010); libname user '/SAS_temp/userb'; %let state=29; %let stab=mo; %let ustab=%upcase(&stab); %let outset=mouas2010; %let aggbyvars=ur ua county; %let aggids=; title "&pgm -Aggregate Block Level SF1 Data to Newly Defined 2012 UAs"; %INCLUDE SASCode(CalcMedian) ; *<---from the California SDC, Aug. 2011---; /* ========================begin comment==================================== *---Generate the $uaname and $uatype format codes that take a UA code and return a name / UA type---; filename text '/pub/sas/formats/Suaname.sas'; %genfmat(sasin=georef.usuas2012,argvar=ua,arglen=5,labelvar=areaname,labellen=120,fmatname=uaname) ; filename text '/pub/sas/formats/Suatype.sas'; %genfmat(sasin=georef.usuas2012,argvar=ua,arglen=5,labelvar=uatype,fmatname=uatype) ; ==========================end comment====================================== */ options compress=binary; *<======================IMPORTANT!!!========================; /* ========================begin comment==================================== *----Step 1: Create, sort and filter the input data set by merging block level sf1 with the correlation list with new UA and UR codes; data aggin; merge sf1.moblocks(in=insf1 keep=county tract block sumlev _numeric_) georef.moblk2ur10(in=inclist); by county tract block; 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; 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 p1i1--p39Ii20 h1i1--h17Ii21 IntPtLon IntPtLat AreaSQMI LandSQMI AreaLand AreaWatr, means=IntPtLon IntPtLat, mweights=AreaSQMI AreaSQMI, agglvls=3,grand=yes, debug=0) run; ==========================end comment====================================== */ data sf1.&outset (label="Mo Urban Areas and U/R portions as of 2012" compress=binary); length SumLev $3 Geocomp $2 State Stab $2 UA $5 UR $1 UAType $1 County $5 Geocode $11 esriid $10 Areaname $64; retain state "&state" stab "&stab"; set aggout; *====================================Here is where sumlev, geocode and areaname need to be assigned=====; geocomp='00'; if ur=' ' and _lvl_ ne 99 then delete; *--10 blocks not assigned a code (zero pop and hus) ---; Select (_lvl_); when(1) do; SumLev='430'; if ua=' ' then ua='99999'; geocode=ua||'-'||county; Areaname=trim(put(ua,$uaname.))||" / "||put(county,$county.); if ua='99999' then Areaname="Remainder (rural portion) of "||put(county,$county.); if ua ne '99999' then uatype=put(ua,$uatype.); end; when(2) do; SumLev='410'; if ua=' ' then ua='99999'; geocode=ua||'-'||state; Areaname=trim(put(ua,$uaname.)); if ua='99999' then Areaname="Remainder (rural portion) of "||put(state,$state.); if index(areaname,'--') then areaname=trim(areaname)|| " (&ustab portion)"; if ua ne '99999' then uatype=put(ua,$uatype.); end; when(3) do; SumLev='040'; if ur='U' then geocomp='01'; else geocomp='43'; geocode=state; Areaname=trim(put(state,$state.))|| '-' || trim(put(geocomp,$geocomp.)) || ' portion' ; end; when(99) do; Sumlev='040'; Areaname=put(state,$state.); geocode=state; end; otherwise do; put _lvl_= " not expected ****"; abort abend; end; end; *--select _lvl_ ---; esriid=compress(geocode,'-'); label UA="UA Ubanized Area or Urban Cluster" UR="Urban/Rural"; *---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 data=sf1.&outset; by sumlev geocomp geocode; run; proc print data=sf12010.&outset(keep=_character_ p1i1 pop100 hu100); by sumlev geocomp state; id ua ur uatype areaname p1i1 pop100 hu100 ; title2 "sf12010.&outset"; run;