x cd /pub/data/acs2009/Tools; %let pgm=acspopests; filename pgm "&pgm..sas"; *---Part of the "CPR" estimating of ACS data for smaller counties (w. < 65000 pop) process. We want to start our new estimates by tapping into data from the official Census intercensal estimates. jgb, 1/26/2009 (original version for 2007 data), 11/09 - version for 2008 data. 1/26/2011 for 2009 data. Results are stored in the cprdata subdir for this acs vintage year (2009). ----*; %let debug=1; %let year=2009; *<---the data year. Correspongs to the data directory we submit from (e.g. acs2008/Tools) ---; %let yearm1=%eval(&year-1); %let yearm2=%eval(&year-2); %let yr=%substr(&year,3,2); %let yrm2=%substr(&yearm2,3,2); %let myrsfx=&yrm2._&yr; *--if year=2008 then myrsfx=06_08 --; %let casrhlyr=09; *--The latest year for which we have casrh estimates. We put data for all years, including earlier ones. You can be accessing data for 2006 in dataset mocasrh07.----; title "acs&year./Tools/&pgm : Estimate ACS pop estimates-based data for smaller counties for &year"; libname popests '/pub/data/popests' access=readonly; libname cprdata "/pub/data/acs&year./cprdata"; %libname(acs&year); libname corrlst '/pub/data/corrlst'; libname nchsbri '/pub/data/popests/nchsbri' access=readonly; %*let state=17; %*let stab=il; %let state=29; %let stab=mo; options nosource; /* =======================Begin comment================ ======================End comment================== */ options source; title2 "Single Year Data - &year"; *-------------------1. Process equivalency files to get links for counties with no acs20xx data to "Parent PUMAs"--; %global bigcos; proc sql noprint; select put(county,$5.) as c into :bigcos separated by ' ' from acs&year..allgeos where state="&state" and sumlev='050'; %put &bigcos; quit; proc summary data=corrlst.sbg2k_puma_&stab (where=(pop2k and index("&bigcos",county)=0) ) noprint nway; var pop2k; class county puma5; output out=countypumas sum=; run; proc sort; by county descending pop2k; run; data cprdata.&stab.cnty_puma&yr(label="Smaller county to PUMA equiv for &year 1-yr ACS allocations"); **merge countypumas(in=in1) acs&year..allgeos3yr(in=in3yr keep=sumlev state county where=(sumlev='050' and state="&state")); *--the allgeos3yr set was not ready yet so we used the profile set instead---; merge countypumas(in=in1) acs&year..usmcdcprofiles3yr(in=in3yr keep=sumlev state county where=(sumlev='050' and state="&state")); by county; if not first.county and last.county then put _all_; if first.county; fipco=county; retain size 's'; if in1; if in3yr then size='m'; else size='s'; *--size is m for medium (20 to 65) and s for small (<20k). --; drop _: sumlev state; run; title3 "&syslast.: Equivalency File Relating Small and Medium-size Counties and PUMAs (from mable-based bg level equivalency files)"; proc print data=cprdata.&stab.cnty_puma&yr N; id county; format county $county.; run ; *-----------------2. Process the latest single-year official county estimates to get basic pop counts by age & gender. Use NCHS special tab----; data cprdata.&stab.agedata&yr; length Year $4 County $5 default=5; *---This set statement never reads any actual data. It is just to set up the pdv with attributes of the keeper variables.---; if 0 then set acs&year..usmcdcprofiles(keep= TotPop Age0_4 Age5_9 Age10_14 Age15_19 Age20_24 Age25_34 Age35_44 Age45_54 Age55_59 Age60_64 Age65_74 Age75_84 Over85 Under18 Over18 Over21 Over62 Over65 Males Over18Males Over65Males Females Over18Females Over65Females Over16 Over16Females Over15 Women15to50 Women15to19 Women20to34 Women35to50 Over25 Over5 Over1); set nchsbri.&stab.nchsbridged20xx_sumry(where=(year="&year" & sumlev="050" ) keep=sumlev county year age Total Male Female ); by county; array _age_ (13) Age0_4 Age5_9 Age10_14 Age15_19 Age20_24 Age25_34 Age35_44 Age45_54 Age55_59 Age60_64 Age65_74 Age75_84 Over85; *---the last 3 variables in this array are NOT in the acs profile dataset but we keep them to help estimate other universe vars-; array _other(*) Under18 Over18 Over21 Over62 Over65 Males Over18Males Over65Males Females Over18Females Over65Females Over16 Over16Females Over15 Women15to50 Women15to19 Women20to34 Women35to50 Over3 Over25 Over5 Over1 Over3 Age5_15 Age16_64; retain; if first.county then do; TotPop=.; do _i=1 to 13; _age_{_i}=0; end; _nother=dim(_other); do _i=1 to _nother; _other{_i}=0; end; end; if age=' ' then Totpop=total; else do; length _age 8; _age=age; *<--convert to numeric--; if _age le 4 then _i=1; else if _age le 9 then _i=2; else if _age le 14 then _i=3; else if _age le 19 then _i=4; else if _age le 24 then _i=5; else if _age le 34 then _i=6; else if _age le 44 then _i=7; else if _age le 54 then _i=8; else if _age le 59 then _i=9; else if _age le 64 then _i=10; else if _age le 74 then _i=11; else if _age le 84 then _i=12; else _i=13; _age_{_i}= _age_{_i}+ total; if _age lt 18 then Under18+total; else Over18+total; if _age ge 21 then Over21+total; if _age ge 62 then Over62+total; if _age ge 65 then Over65+total; Males + Male; if _age ge 18 then Over18Males+Male; if _age ge 65 then Over65Males+Male; Females + Female; if _age ge 18 then Over18Females+Female; if _age ge 65 then Over65Females+Female; if _age ge 16 then over16+total; if _age ge 16 then over16Females+Female; if _age ge 15 then over15+total; if 15 <= _age <= 50 then Women15to50+Female; if 15 <= _age <= 19 then Women15to19+Female; if 20 <= _age <= 34 then Women20to34+Female; if 34 <= _age <= 50 then Women35to50+Female; if _age ge 3 then Over3+total; if _age ge 25 then Over25+total; if _age ge 5 then Over5+total; if 5 <= _age <= 15 then Age5_15+total; if 16 <= _age <= 64 then Age16_64+total; if _age ge 1 then Over1+total; end; if last.county then output; *<----1 obs per county. We do our own summing----; keep county TotPop age0_4 -- Over85 Under18 -- Over1 Over3 Over5 Over15 Age5_15 Age16_64; format TotPop Over3 Age5_15 age16_64 comma9.; run; *---Calculate the median age and merge that with the other age-based data---; data numericage/view=numericage; set nchsbri.&stab.nchsbridged20xx_sumry(where=(year="&year" & sumlev="050" and age ne ' ') keep=year sumlev age county total ); length newage 8; newage=age; drop age; rename newage=age; run; proc summary data=numericage nway; class county; freq total; var age; output out=medianages(drop=_type_ _freq_) median=MedianAge; run; data cprdata.&stab.agedata&yr; merge cprdata.&stab.agedata&yr medianages; by county; format medianAge 4.1; run; proc print data=cprdata.&stab.agedata&yr(obs=10); id county; title3 "Age Data"; run ; *-----------------3. Process latest official county estimates by race (cannot use nchs bridged, go with casrh numbers----; data cprdata.&stab.racedata&yr; length County $5; *---This set statement never reads any actual data. It is just to set up the pdv with attributes of the keeper variables.---; if 0 then set acs&year..usmcdcprofiles (keep= OneRace White1 Black1 Indian1 Asian1 HawnPI1 Other1 MultiRace White2 Black2 Indian2 Asian2 HawnPI2 Other2 HispanicPop NonHispPop NonHispWhite NonHispBlack NonHispAmInd NonHispAsian NonHispHawnPI); set popests.&stab.casrh&casrhlyr( keep=county sumtype Race Hispanic popest_&year rename=(popest_&year=_est)); where sumtype in ('R','r','h','rh','t'); by county; retain; array racedata (*) OneRace White1 Black1 Indian1 Asian1 HawnPI1 Other1 MultiRace White2 Black2 Indian2 Asian2 HawnPI2 Other2 HispanicPop NonHispPop NonHispWhite NonHispBlack NonHispAmInd NonHispAsian NonHispHawnPI; if first.county then do; do _i=1 to dim(racedata); racedata{_i}=0; end; end; select (sumtype); when ('R') do; if race='07' then White2=_est; else if race='08' then Black2=_est; else if race='09' then Indian2=_est; else if race='10' then Asian2=_est; else if race='11' then HawnPI2=_est; else _error_=1; end; when ('r') do; if race='01' then White1=_est; else if race='02' then Black1=_est; else if race='03' then Indian1=_est; else if race='04' then Asian1=_est; else if race='05' then HawnPI1=_est; else if race='06' then MultiRace=_est;else _error_=2; end; when ('h') do; if hispanic='1' then NonHispPop=_est; else if hispanic='2' then HispanicPop=_est; else _error_=3; end; when('rh') if hispanic='1' then do; if race='01' then NonHispWhite=_est; else if race='02' then NonHispBlack=_est; else if race='03' then NonHispAmInd=_est; else if race='04' then NonHispAsian=_est; else if race='05' then NonHispHawnPI=_est; else if race ne '06' then _error_=4; end; when('t') do; * put 'Total pop for ' county ' is ' _est; _totpop=_est; end; end; drop sumtype race hispanic _:; *** drop Other1 Other2; *<------We do not have estimates for these 2 items on our casrh datasets---------------------------; if last.county then do; OneRace=_totpop - MultiRace; Other1=OneRace - sum (of white1 black1 asian1 indian1 HawnPI1); Other2=.; *--cannot derive it---; output; end; *--Fix labels on NonHisp variables--; %macro labl(race,racelabl); %if %superq(racelabl)=%str() %then %let racelabl=∽̱ NonHisp&race="Non-hispanic &racelabl alone" %mend; options mprint; label %labl(white) %labl(black) %labl(AmInd,American Indian+) %labl(Asian) %labl(HawnPI,Native Hawaiian+) ; run; proc print data=cprdata.&stab.racedata&yr (obs=10); title3 "Race Data"; run cancel; *---------------------4. Complete this phase by adding in the latest HU estimates and then merging the 4 sets together-------; data huests; set popests.ushuest&year(where=(state="&state" and sumlev="050") keep=sumlev state county huest_&year); run; title3 "cprdata.&stab.estimates1yr"; data cprdata.&stab.estimates1yr; length State $2 SumLev $3 fipco County PUMA5 $5; retain Year "&year"; merge cprdata.&stab.cnty_puma&yr (keep=county puma5) cprdata.&stab.agedata&yr cprdata.&stab.racedata&yr huests; by county; fipco=county; format fipco $5. county $county.; if index("&bigcos",county)=0; *<---delete the larger counties where we do not need these data---; run; %content (cprdata.&stab.estimates1yr); proc print data=cprdata.&stab.estimates1yr (obs=10); id fipco; run; *======================================Phase II: Create 3-year average data from the various estimates using latest 3 years worth===; title2 "Multi-Year Data: &yearm2 to &year"; *---------2M. Process the latest 3 single-year official county estimates of pop counts by age & gender. Use NCHS special tab----; data cprdata.&stab.agedata&myrsfx; length Year $4 County $5 default=5; *---This set statement never reads any actual data. It is just to set up the pdv with attributes of the keeper variables.---; if 0 then set acs&year..usmcdcprofiles(keep= TotPop Age0_4 Age5_9 Age10_14 Age15_19 Age20_24 Age25_34 Age35_44 Age45_54 Age55_59 Age60_64 Age65_74 Age75_84 Over85 Under18 Over18 Over21 Over62 Over65 Males Over18Males Over65Males Females Over18Females Over65Females Over16 Over16Females Over15 Women15to50 Women15to19 Women20to34 Women35to50 Over25 Over5 Over1); set nchsbri.&stab.nchsbridged20xx_sumry(where=(year in("&yearm2","&yearm1","&year") & sumlev="050" ) keep=sumlev county year age Total Male Female ); by county year; array _age_ (13) Age0_4 Age5_9 Age10_14 Age15_19 Age20_24 Age25_34 Age35_44 Age45_54 Age55_59 Age60_64 Age65_74 Age75_84 Over85; *---the last 3 variables in this array are NOT in the acs profile dataset but we keep them to help estimate other universe vars-; array _other(*) Under18 Over18 Over21 Over62 Over65 Males Over18Males Over65Males Females Over18Females Over65Females Over16 Over16Females Over15 Women15to50 Women15to19 Women20to34 Women35to50 Over3 Over25 Over5 Over1 Over3 Age5_15 Age16_64; retain; retain Years "&yearm2. to &year."; if first.county then do; TotPop=0; do _i=1 to 13; _age_{_i}=0; end; _nother=dim(_other); do _i=1 to _nother; _other{_i}=0; end; _nyears=0; end; if first.year then _nyears+1; *---we count the years as a double check to make sure we always have exactly 3!--; if age=' ' then Totpop+total; else do; length _age 8; _age=age; *<--convert to numeric--; if _age le 4 then _i=1; else if _age le 9 then _i=2; else if _age le 14 then _i=3; else if _age le 19 then _i=4; else if _age le 24 then _i=5; else if _age le 34 then _i=6; else if _age le 44 then _i=7; else if _age le 54 then _i=8; else if _age le 59 then _i=9; else if _age le 64 then _i=10; else if _age le 74 then _i=11; else if _age le 84 then _i=12; else _i=13; _age_{_i}= _age_{_i}+ total; if _age lt 18 then Under18+total; else Over18+total; if _age ge 21 then Over21+total; if _age ge 62 then Over62+total; if _age ge 65 then Over65+total; Males + Male; if _age ge 18 then Over18Males+Male; if _age ge 65 then Over65Males+Male; Females + Female; if _age ge 18 then Over18Females+Female; if _age ge 65 then Over65Females+Female; if _age ge 16 then over16+total; if _age ge 16 then over16Females+Female; if _age ge 15 then over15+total; if 15 <= _age <= 50 then Women15to50+Female; if 15 <= _age <= 19 then Women15to19+Female; if 20 <= _age <= 24 then Women20to34+Female; if 34 <= _age <= 50 then Women35to50+Female; if _age ge 3 then Over3+total; if _age ge 25 then Over25+total; if _age ge 5 then Over5+total; if 5 <= _age <= 15 then Age5_15+total; if 16 <= _age <= 64 then Age16_64+total; if _age ge 1 then Over1+total; end; if last.county then do; if _nyears ne 3 then do; put //'***Logic problem: did not get expected 3 years of data for county....aborting***** ' / _all_; abort abend; end; TotPop=round(TotPop/3); do _i=1 to 13; _age_{_i}=round( _age_{_i}/3); end; _nother=dim(_other); do _i=1 to _nother; _other{_i}=round( _other{_i}/3); end; output; *<----1 obs per county. We do our own summing----; end; keep Years county TotPop age0_4 -- Over85 Under18 -- Over1 Over3 Over5 Over15 Age5_15 Age16_64; format TotPop Over3 Age5_15 age16_64 comma9.; run; *---Calculate the median age and merge that with the other age-based data---; data numericage3/view=numericage3; set nchsbri.&stab.nchsbridged20xx_sumry(where=(year in("&year","&yearm1","&yearm2") & sumlev="050" and age ne ' ') keep=year sumlev age county total ); length newage 8; newage=age; drop age; rename newage=age; run; proc summary data=numericage3 nway; class county; freq total; var age; output out=medianages3(drop=_type_ _freq_) median=MedianAge; run; data cprdata.&stab.agedata&myrsfx; merge cprdata.&stab.agedata&myrsfx medianages3; by county; format medianAge 4.1; run; proc print data=cprdata.&stab.agedata&myrsfx (obs=10); by Years; id county; title3 "Age Data "; run ; *-----------------3M. Process latest official county estimates by race (cannot use nchs bridged, go with casrh numbers----; data cprdata.&stab.racedata&myrsfx; length County $5; *---This set statement never reads any actual data. It is just to set up the pdv with attributes of the keeper variables.---; if 0 then set acs&year..usmcdcprofiles (keep= OneRace White1 Black1 Indian1 Asian1 HawnPI1 Other1 MultiRace White2 Black2 Indian2 Asian2 HawnPI2 Other2 HispanicPop NonHispPop NonHispWhite NonHispBlack NonHispAmInd NonHispAsian NonHispHawnPI); set popests.&stab.casrh&casrhlyr( keep=county sumtype Race Hispanic popest_&year popest_&yearm1 popest_&yearm2 rename=(popest_&year=_est1 popest_&yearm1=_est2 popest_&yearm2=_est3)); where sumtype in ('R','r','h','rh','t'); by county; retain; array racedata (*) OneRace White1 Black1 Indian1 Asian1 HawnPI1 Other1 MultiRace White2 Black2 Indian2 Asian2 HawnPI2 Other2 HispanicPop NonHispPop NonHispWhite NonHispBlack NonHispAmInd NonHispAsian NonHispHawnPI; if first.county then do; do _i=1 to dim(racedata); racedata{_i}=0; end; end; select (sumtype); when ('R') do; if race='07' then White2=round(mean(of _est1-_est3)); else if race='08' then Black2=round(mean(of _est1-_est3)); else if race='09' then Indian2=round(mean(of _est1-_est3)); else if race='10' then Asian2=round(mean(of _est1-_est3)); else if race='11' then HawnPI2=round(mean(of _est1-_est3)); else _error_=1; end; when ('r') do; if race='01' then White1=round(mean(of _est1-_est3)); else if race='02' then Black1=round(mean(of _est1-_est3)); else if race='03' then Indian1=round(mean(of _est1-_est3)); else if race='04' then Asian1=round(mean(of _est1-_est3)); else if race='05' then HawnPI1=round(mean(of _est1-_est3)); else if race='06' then MultiRace=round(mean(of _est1-_est3));else _error_=2; end; when ('h') do; if hispanic='1' then NonHispPop=round(mean(of _est1-_est3)); else if hispanic='2' then HispanicPop=round(mean(of _est1-_est3)); else _error_=3; end; when('rh') if hispanic='1' then do; if race='01' then NonHispWhite=round(mean(of _est1-_est3)); else if race='02' then NonHispBlack=round(mean(of _est1-_est3)); else if race='03' then NonHispAmInd=round(mean(of _est1-_est3)); else if race='04' then NonHispAsian=round(mean(of _est1-_est3)); else if race='05' then NonHispHawnPI=round(mean(of _est1-_est3)); else if race ne '06' then _error_=4; end; when('t') do; * put 'Total pop for ' county ' is ' _est; _totpop=round(mean(of _est1-_est3)); end; end; drop sumtype race hispanic _:; *** drop Other1 Other2; *<------We do not have estimates for these 2 items on our casrh datasets---------------------------; if last.county then do; OneRace=_totpop - MultiRace; Other1=OneRace - sum (of white1 black1 asian1 indian1 HawnPI1); Other2=.; *--cannot derive it---; output; end; *--Fix labels on NonHisp variables--; %macro labl(race,racelabl); %if %superq(racelabl)=%str() %then %let racelabl=∽̱ NonHisp&race="Non-hispanic &racelabl alone" %mend; options mprint; label %labl(white) %labl(black) %labl(AmInd,American Indian+) %labl(Asian) %labl(HawnPI,Native Hawaiian+) ; run; proc print data=cprdata.&stab.racedata&myrsfx (obs=10); title3 "Race Data"; run ; *---------------------4M. Complete this phase by adding in recent HU estimates and then merging the 4 multi-year sets together-------; data huests3; set popests.ushuest&year (where=(state="&state" and sumlev="050") keep=sumlev state county huest_&year huest_&yearm1 huest_&yearm2 ); /* =======================Begin comment================ merge popests.ushuest&year (where=(state="&state" and sumlev="050") keep=sumlev state county huest_&year in=in1) popests.ushuest&yearm1(where=(state="&state" and sumlev="050") keep=sumlev state county huest_&yearm1 in=in2) popests.ushuest&yearm2(where=(state="&state" and sumlev="050") keep=sumlev state county huest_&yearm2 in=in3); by county; if not (in1 and in2 and in3) then do; put / '****HU estimate missing for this county: ' county= in1= in2= in3=; _nbad+1; if _nbad ge 10 then abort abend; drop _nbad; end; ======================End comment================== */ huest=mean(of huest_:); drop huest_: ; run; title3 "cprdata.&stab.estimates3yr"; data cprdata.&stab.estimates3yr; length State $2 SumLev $3 fipco County PUMA5 $5; retain Years "&yearm2. to &year."; merge cprdata.&stab.cnty_puma&yr (keep=county puma5 size in=notbig) cprdata.&stab.agedata&myrsfx cprdata.&stab.racedata&myrsfx huests3; by county; if notbig; *<---keep data only for counties with under 20000 pop who need 3-year estimates done. (And for m size as well for test!)---; fipco=county; format fipco $5. county $county.; run; %content (cprdata.&stab.estimates3yr); proc print data=cprdata.&stab.estimates3yr (obs=10); id fipco; run;