x cd /pub/data/corrlst/Tools; %let pgm=usco2puma_byrace; filename pgm "&pgm..sas"; *---Per request from Eduardo Martins, American Human Development Project, Columbia U. NYC: "What I would like to do is to calculate allocation factors for each race group, rather than use total population. I don't suppose it is possible with GeoCorr, right? Is there any assistance you can give me on how I could accomplish this?" With followup we agreed upon specific race-based weights: "White Alone, not Hispanic Black or African American alone, not Hispanic Asian or Pacific Islander Alone, not Hispanic American Indian and Alaska Native alone, not Hispanic Hispanic, of any race" and also that we would tweak those weight variables to make them conform to 2007 official pop estimates at the county level. jgb, 12/08. This program is being sponsored by (i.e. paid for) by measureofamerica.org . ----*; libname user '/SAS_temp/userb'; libname pubdata3 "/pub/data3"; %libname (popests); %libname (mable2k); %libname(acs2007); libname corrlst '/pub/data/corrlst'; libname temp '/pub/data/corrlst/temp'; *---Get PUMA level race counts for 2007 from ACS, 1-year data with 3-year as "backup"---; data temp.curpumacounts(index=(state)); *---With the update stmt we replace all 3-year numbers with the equi 1-year values EXCEPT in cases where values are missing, in which case the 3yr values actually get used (missing values do not update the master values)---; update acs2007.usmcdcprofiles3yr(where=(sumlev='795') keep=sumlev geoid state totpop hispanicpop nonhispwhite nonhispblack nonhispamind nonhispasian in=in3) acs2007.usmcdcprofiles(where=(sumlev='795') keep=years sumlev geoid state totpop hispanicpop nonhispwhite nonhispblack nonhispamind nonhispasian rename=(years=year) in=in1 ); by state geoid; length puma5 $5; puma5=substr(geoid,10,5); if not in1 then do; *----In run against MD we had NO 1-year data for that states PUMAs. Will rerun later after fixing this.---; put "***No single year data for PUMA*** " state= geoid= puma5=; end; drop geoid; run; proc print data=temp.curpumacounts (where=(state='28')); title2 "temp.curpumacounts (MS only)"; run; %macro renameaf(v); rename afact=afact_&v; if first.county and last.county and afact=. then afact=1.0; %mend renameaf; %macro docorrwts(stab,vars=pop07 hispanic whitenh blacknh amindnh asiannh ); %local i; %do i=1 %to 6; %let popvar=%scan(&vars,&i); %if &popvar=%str() %then %goto fini; %corrwt(setin=corrwtin,setout=&stab.co2puma_&popvar,wtvar=&popvar, g1=county,g2=puma5,idvars=state year,keepwt=1,exitout=renameaf(&popvar)) ***proc print data=&syslast (obs=40); ***title2 "&syslast"; run; %end; %fini: *--And, now merge them all into a single data set with a set of weight and afact variables--; %let nsets=%eval(&i-1); %mend docorrwts; %**let state=10; %**let stab=de; %macro doit(state,stab); title "Processing state: &state &stab"; x cd /pub/data3; x unzip -q pl942000 &stab.geos.sas7bdat &stab.geos.sas7bndx &stab.detail.sas7bdat &stab.detail.sas7bndx; data aggin&stab.v /view=aggin&stab.v; merge pubdata3.&stab.geos(keep=geo_id county tract block sumlev where=(sumlev='750') in=blksummary ) pubdata3.&stab.detail(in=indetail where=(race_id in(1,2,4,8) or hispanic)); by geo_id; if blksummary and indetail; if hispanic then race_id=5; *--Making up our own codes here. If the person is hispanic then we treat that like a race; *---recode the race_ids to keep them simple, 1 to 4--; if race_id=4 then race_id=3; else if race_id=8 then race_id=4; drop sumlev geo_id state voteage; run; proc sort data=aggin&stab.v out=aggin&stab.; by county tract block; run; data aggin&stab.2; merge aggin&stab.(in=inpl94 drop=hispanic) mable2k.&stab.v2(in=inmable keep=county county02 tract block puma5 pop2k where=(pop2k)) ; by county tract block; if not (inmable) then do; _nbad+1; if _nbad le 25 then do; put _all_; end; end; array _count(5) whiteNH blackNH amindNH asianNH Hispanic ; retain whiteNH--Hispanic; if first.block then do _i=1 to 5; _count(_i)=0; end; if inpl94 then _count(race_id) + persons; if last.block then do; if not inpl94 then NoDetailPop=pop2k; else NoDetailPop=0; output; *---1 obs per block with PUMA code attached and our 5 race figures totaled---; end; drop _: persons race_id ; %if &state=08 or &state=51 %then %do; *---county values have been changed since 2000 so we need to now substitute the current county codes----; rename county=county2k county02=county; %end; %else %str( drop county02;) ; run; proc print data=_last_(obs=40); title2 "aggin&stab.2"; run; proc print data=aggin&stab.2(where=(nodetailpop) keep=county tract block nodetailpop); sum nodetailpop; title2 "Blocks Not matched on pl94"; run; proc sort data=aggin&stab.2; by puma5 county ; run; %agg(setin=aggin&stab.2,setout=cntypumasums,aggby=puma5 county, aggvars=whiteNH blackNH amindNH asianNH Hispanic pop2k, naggvars=6, agglvl=2); proc sort data=cntypumasums; by puma5 county; run; proc print data=_last_(obs=240); title2 "cntypumasums"; run; *---Merge the puma-county data with the current puma level estimates and use to create growth-adjustment-factors (gafs) for the categories; data corrwtin; merge cntypumasums (in=insums) temp.curpumacounts (in=incurcounts where=(state="&state")); by puma5; if not (insums and incurcounts) then do; put '***No match for this puma: ' state= puma5= insums= incurcounts= ; delete; end; *---when processing a puma total obs we create the gafs, which we then apply to adjust the various pop counts on the subsequent puma/cnty summary observations.---; if _lvl_=2 then do; array _gaf(6) _gaf1-_gaf6; retain _gaf: ; _gaf{1}=totpop/pop2k; _gaf{2}=NonHispWhite/whiteNH; if whiteNH <=0 | NonHispWhite < 0 then _gaf{2}=1; _gaf{3}=NonHispBlack/blackNH; if blackNH <=0 | NonHispBlack=< 0 then _gaf{3}=1; _gaf{4}=NonHispAmind/amindNH; if AmindNH <=0 | NonHispAmind=< 0 then _gaf{4}=1; _gaf{5}=NonHispAsian/asianNH; if AsianNH <=0 | NonHispAsian=< 0 then _gaf{5}=1; _gaf{6}=HispanicPop/Hispanic; if Hispanic <=0 | HispanicPop=< 0 then _gaf{6}=1; delete; end; else do; array _count(6) pop2k whiteNH -- Hispanic; do _i=1 to 6; _count{_i}=round ( _count{_i} * _gaf{_i} ); end; if _n_ le 10 then put / _all_; end; State="&state"; output; drop totpop nonhisp: HispanicPop; drop _: ; rename pop2k=pop07; *<====; run; proc print data=&syslast(obs=40); title2 "&syslast"; run; proc sort data=corrwtin; by county puma5; run; options mprint; %docorrwts (&stab); data temp.&stab.co2puma_byrace; merge &stab.co2puma_pop07 &stab.co2puma_hispanic &stab.co2puma_whitenh &stab.co2puma_blacknh &stab.co2puma_amindnh &stab.co2puma_asiannh; by county puma5; run; proc print data=&syslast(obs=40); title2 "&syslast"; by state year; id county puma5; run; %mend doit; options mprint; %**dostates(01) ; %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17); %dostates(18 19 20 21 22 23 24 25 26 27 28 29 30 31); %dostates(32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56); *----And now concatenate all the 51 temp data sets to get the US single data set----; %macro setit(state,stab); temp.&stab.co2puma_byrace %mend setit; data temp.USco2puma_byrace; set %dostates(mac=setit) open=defer ; run;