x cd /pub/data/acs2007/Tools; %let pgm=indicators_cpr1; filename pgm "&pgm..sas"; *--- Create the key indicators data set for Missouri and its counties, as available for the latest single year, 2007. jgb, 10-30-2008. ----*; *<==============When updating for a new year be sure to change all occurrences of acs2007 to acsXXXX, where XXXX is the new year=; %let debug=1; %let libout=temp; %let year=2007; *<---the data year. Correspongs to the data directory we submit from (e.g. acs2007/Tools) ---; %let yr=%substr(&year,3,2); %let casrhlyr=07; *--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 "acs2007/Tools/&pgm : Estimate ACS key_indicators data for smaller counties for &year"; libname popests '/pub/data/popests' access=readonly; libname user '/SAS_temp/user'; libname temp "/pub/data/acs2007/temp"; libname acs2007 '/pub/data/acs2007' access=readonly; 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; *-------------------1. Process equivalency files to get links for counties with no acs2007 data to "Parent PUMAs"--; %global bigcos; proc sql noprint; select county into :bigcos separated by ' ' from acs2007.allgeos where state="&state" and sumlev='050'; %put &bigcos; select name into :acsvars1 separated by ' ' from acs2007.variables( where=( name ^=: 'Pct' and substr(table,1,2) in ('1.','2.'))); %put &acsvars1; select name into :acsvars2 separated by ' ' from acs2007.variables( where=( name ^=: 'Pct' and substr(table,1,2) in ('3.','4.'))); %put &acsvars2; 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 corrlst.&stab.cnty_puma(label='Smaller county to PUMA equiv for 2006 acs allocations'); set countypumas; by county; if not first.county and last.county then put _all_; if first.county; fipco=county; drop _: ; run; title2 "Equivalency File Relating Smaller Counties and PUMAs (from mable-based bg level equivalency files)"; proc print data=corrlst.&stab.cnty_puma N; id county; format county $county.; run cancel; *-----------------2. Process the latest official county estimates to get basic pop counts by age & gender. Use NCHS special tab----; data temp.&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 acs2007.usmcdcprofiles(keep= 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 Women20to24 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 Women20to24 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 <= 24 then Women20to24+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 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 temp.&stab.agedata&yr; merge temp.&stab.agedata&yr medianages; by county; format medianAge 4.1; run; proc print data=temp.&stab.agedata&yr; id county; title2 "Age Data"; run cancel; *-----------------3. Process latest official county estimates by race (cannot use nchs bridged, go with casrh numbers----; data temp.&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 acs2007.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=sum(of White1 --HawnPI1 Other1); 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=temp.&stab.racedata&yr (obs=40); title2 "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; title2 "temp.&stab.estimates&yr"; data temp.&stab.estimates&yr; length State $2 SumLev $3 fipco County PUMA5 $5; retain DataYear "&year"; merge corrlst.&stab.cnty_puma (keep=county puma5) temp.&stab.agedata&yr temp.&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 (temp.&stab.estimates&yr); proc print data=temp.&stab.estimates&yr (obs=10); id fipco; run; *----see wormcan2.sas for further processing----;