x cd /pub/data/acs2007/Tools; %let pgm=applycpr3yr_jgb; filename pgm "&pgm..sas"; *---Allocated ACS data for smaller (<20000) Mo counties using 3yr period data and the County-PUMA Ration ("cpr") method. Specifically, this module is set up to handle generating 3yr period estimates for all MO counties except those over 65K using ACS 2005-2007 3yr period estimates. The CPR ratios are derived from the county and PUMA level summaries in the sf32kacs filetype directories. Basic demographic "starter" data comes from the census estimates datasets as processed in job acspopests in this same Tools directory. Redundnant coding being done by bce so that we can compare results and evaluate. jgb, Jan, 2009 ----*; %let year=2007; %let yr=%substr(&year,3,2); %let yearm1=%eval(&year-1); %let yearm2=%eval(&year-2); %let yrm1=%substr(&yearm1,3,2); %let yrm2=%substr(&yearm2,3,2); %let myrsfx=&yrm2._&yr; *--so it it 05_07 when year=2007---; %let debug=1; title "&pgm: Estimate ACS data for smaller counties for 3-Year Period &yearm2 to &year"; libname user '/SAS_temp/user'; libname temp "/pub/data/acs&year./temp"; libname acs "/pub/data/acs&year"; libname cprdata "/pub/data/acs&year./cprdata"; libname sf32kacs "/pub/data/sf32kacs"; %let state=29; %let stab=mo; *---Code here to create the input data source via merging of data from the sf32kacs directory (county and puma data), the latest 3-year period estimates for the PUMAs, and the 3-year pop estimates data created in the acspopests setup.--; proc contents data=acs.usmcdcprofiles3yr(keep=_numeric_) noprint out=profilevars(keep=name); run; %global moevars; proc sql noprint; **select put(county,$5.) into :bigcos separated by ' ' from acs.allgeos where state="&state" and sumlev='050'; select name into :moevars separated by ' ' from profilevars where name contains 'MOE'; quit; %***put &moevars; options nosource; /* =======================Begin comment================ ======================End comment================== */ options source; *---Use utility macro to generate the rename code to be used in subsequent data step to append a sfx to all numeric vars-; %genrenam(sf32kacs.sf3counties,xvars=state county sumlev,sfx=_c2x) data cnty2k; merge sf32kacs.sf3counties ( &rename where=(state="&state" and sumlev="050") ) cprdata.&stab.cnty_puma&yr (in=ingeos); by county; if size='s' or size='m'; *---for now we keep the m size counties and estimate their data for checking purposes--; run; data temp.&stab.cos2kests(label="2k census county data with _c2x varname suffixes + &yr estimates" ); merge cnty2k(in=in2kdata) cprdata.&stab.estimates3yr(in=inests) cprdata.&stab.cnty_puma&yr(in=inclist); by county; if in2kdata; if not (in2kdata and inests and inclist) then do; put / '*****ERROR: county not matched on county-puma equivalency dataset or on estimates dataset ***** ' / _all_; abort abend; end; run; proc sort; by puma5 county; run; %content(temp.&stab.cos2kests); %genrenam(sf32kacs.sf3pumas,xvars=state puma5,sfx=_p2x) data temp.&stab.pumas2k(label="2k census PUMA data with _p2x varname suffixes" ); set sf32kacs.sf3pumas ( &rename where=(state="&state" ) ); run; proc sort; by puma5; run; data pumapros_nomoes; length puma5 $5; set acs.usmcdcprofiles3yr ( drop=&moevars ); where state="&state" and sumlev="795" ; puma5=substr(geoid,10,5); run; %genrenam(pumapros_nomoes,xvars=sumlev state puma5 PctOwnKidsUnder6AllPrntsWork ,sfx=_pacs) data temp.&stab.pumasacs3yr(label="ACS 3yr PUMA data with _pacs varname suffixes" Index=(puma5)); set pumapros_nomoes ( &rename); drop sumlev age: pctage: over: under: ; run; data cprdata.lakeoz(label='Sample work dataset'); *----------------temporary test----------------------*; merge temp.&stab.pumas2k (in=inpuma2k) temp.&stab.pumasacs3yr(in=inpumaacs) temp.&stab.cos2kests(in=incos); by puma5; if incos; *---We may have data for some pumas that are not needed---; if not (inpuma2k and inpumaacs and incos) then do; put '****match not working in test step****' +2 inpuma2k= inpumaacs= incos= puma5= county=; abort abend; end; else if puma5='01300' then output; run; options mprint NOmlogic; %macro applycpr(var,round=1,acsvar=,PctOf= ); %if %superq(acsvar) eq %str() %then %let acsvar=&var; %if %lowcase(%substr(&var,1,3))=%str(pct) and &round=1 %then %let round=.00001; %*--different rounding for pcts--; _cpr=.; if &acsvar._pacs=0 then &acsvar=0; else if &var._p2x then _cpr= &var._c2x/&var._p2x; else _cpr=.; %*---county to PUMA ratio per last available data (census 2k here)-; if _cpr then &acsvar = round(_cpr * &acsvar._pacs,&round); else if &acsvar=. then &acsvar=&var._c2x; %*--we estimate by applying the values ratio to the current puma figure. If no ratio then just carry forward the most recent county figure--; %if %superq(PctOf) ne %str() %then %do; if &PctOf then Pct&acsvar=100*&acsvar / &PctOf; %end; %if &debug %then %do; *** put '***debug: ' _cpr = &var._c2x= &var._p2x= &acsvar._pacs= &acsvar=; %end; %mend applycpr; %macro acprPct(var,PctOf); *---This macro invokes the applycpr macro to estimate a Pct variable and then multiplies that estimated value by the PctOf (Universe) variable to estimate the corresponding count. The var parm is the base name without the leading "Pct"--; %let _pctvar=Pct&var; %applycpr(&_pctvar) &var=round( &_pctvar*.01*&PctOf); %mend acprPct; %macro apcprlst(list,_pctof); %*--utiity macro to invoke the applycpr macro for each variable in the parameter list--; %local i vari; %let i=1; %let vari=%scan(&list,1); %do %while (&vari ne %str()); %applycpr(&vari,Pctof=&_pctof) %let i=%eval(&i+1); %let vari=%scan(&list,&i); %end; %mend apcprlst; %macro dodist(tabnm,sfxs,tabtot); %*---do a distribution table: generalization of dohhinc macro, where we make the table and suffixes parms----; %*--we assume parallel arrays of cell counts and Pct-ages corresponding to those counts with tabtot as the denominator--; %global debug tabsize; %local i _pctvar sfx nsfxs; %let tabsize=%lenlst(&sfxs); _checksum=0; _checksum2=0; _checksum3=0; %do pass=1 %to 2; %*--double pass of table. 1st time we estimate the pcts and the cell counts and keep a check sum. On second pass we adjust the pcts and cell counts to insure they add to our control total, TotHHs.-; %do i=1 %to &tabsize; %let sfx=%scan(&sfxs,&i); %if &pass=1 %then %do; %*---Apply cpr method to estimate the cell count---*; %applycpr(&tabnm&sfx) _checksum + &tabnm&sfx; %end; %else %do; %*---2nd pass. We rake the values to match table control total and calculate pct variables---; %if &i=1 %then %str(if _checksum then _rake=&tabtot/_checksum; ); if _checksum then &tabnm&sfx=round(&tabnm&sfx*_rake); if &tabtot then Pct&tabnm&sfx=100*&tabnm&sfx/&tabtot; _checksum2 + &tabnm&sfx; _checksum3 + Pct&tabnm&sfx; %end; %end; %*--do i loop--; %if &debug and &pass=2 %then %do; put "For table &tabnm : " _checksum= _checksum2= _checksum3= _rake= &tabtot=; if round(_checksum3) ne 100 then do; put "***_checksum3 for Pct&tabnm values does not add to 100 as expected *** " _checksum3= ; end; %end; %end; %*--do pass loop--; %mend dodist; %macro alias(name,alias); &alias._c2x=&name._c2x; &alias._p2x=&name._p2x; &alias._pacs=&name._pacs; drop &alias._: ; %mend alias; *------------------------------Data Step to "apply CPR" method to estimate data for counties for the 3yr period---------; data cprdata.lakeOzarkCounties(label='3yr estimates for small counties allocated using CPR method'); length county $5; if 0 then set acs.usmcdcprofiles3yr(drop=&moevars); *---add more drop vars here to get rid of what we do not want. Allows us to to a double-dash keep to specify what gets kept on output. It is all we specify here.---; set cprdata.lakeOz; Areaname=areaname_c2x; SumLev='050'; geocode=county; geoid='05099US'||county; Period='3cp'; *--3yr, cpr method estimated--; if &debug then put / areaname=; *---We have a bunch of estimates variables that are being loaded but they are counts without pcts. In this section we calculate all those missing Pct variables. Have to be careful, using double-dash lists here.--; array estspcts(*) age0_4--PctOver85 Over5--PctNonHispHawnPI; _nestspcts=dim(estspcts); _icnt=1; _ipct=2; do _i=1 to _nestspcts by 2; *--The array alternates between counts in the odd cells and Pct vars in the even cells. All pcts use Totpop as the denom.--; estspcts(_ipct)=100*estspcts(_icnt)/totpop; _icnt+2; _ipct+2; end; drop _: ; * ------------------------------end estimates pctVar calculations------------------; %applycpr(PctOccHUs,acsvar=PctOccHUs); TotHUs=huest; TotHHs=round(TotHUs*.01*PctOccHUs); OccHUs=TotHHs; %dodist(hhinc, 0 10 15 25 35 50 75 100 150 200, TotHHs) %applycpr(MedianHHInc) %applycpr(AvgHHInc) %applycpr(NumHHEarnings,PctOf=TotHHs) %applycpr(AvgHHEarnings) %applycpr(NumHHSocSec,PctOf=TotHHs) %applycpr(AvgHHSocSec) %applycpr(NumHHRetInc,PctOf=TotHHs) %applycpr(AvgHHRetInc) %applycpr(NumHHSuppSecInc,PctOf=TotHHs) %applycpr(AvgHHSuppSecInc) %applycpr(NumHHPubAssist,PctOf=TotHHs) %applycpr(AvgHHPubAssist) if PctFamHHs_p2x=. then do; PctFamHHs_c2x=100*FamHHs_c2x/TotHHs_c2x; PctFamHHs_p2x=100*FamHHs_p2x/TotHHs_p2x; PctFamHHs_pacs=100*FamHHs_pacs/TotHHs_pacs; end; %applycpr(PctFamHHs) FamHHs=round(PctFamHHs*.01*TotHHs); %dodist(FamHHInc,0 10 15 25 35 50 75 100 150 200,FamHHs) %applycpr(MedianFamInc) %applycpr(AvgFamInc) %applycpr(PCI) NonFamHHs=TotHHs - FamHHs; PctNonFamHHs=100*NonFamHHs/TotHHs; %apcprlst(MedianNonFamInc AvgNonFamInc MedianEarnings MedianEarningsFemale) %applycpr(PctPovUniverse) PovUniverse=round(PctPovUniverse*.01*TotPop); PctPovUniverse=100*PovUniverse/TotPop; *--Poverty universes for 3 age cohorts are estimated by assuming the pu as a pctage of total pop in the cohort is fixed--; PovUniverseUnder18= round( (PovUniverseUnder18_c2x/Under18_c2x)*Under18 ); _age18_64_c2x=Totpop_c2x - Under18_c2x - Over65_c2x; _Age18_64=Totpop - Under18 - Over65; PovUniverse18_64= round( (PovUniverse18_64_c2x/_Age18_64_c2x)*_Age18_64 ); PovUniverseOver65= round( (PovUniverseOver65_c2x/Over65_c2x)*Over65 ); *---edit this drop list to always start with the next variable not yet estimated--; %applycpr(PctPoor) Poor=round( PovUniverse*.01*PctPoor ); %applycpr(PctPoorUnder18) PoorUnder18=round( PctPoorUnder18*.01*PovUniverseUnder18 ); %applycpr(PctPoor18to64) Poor18to64=round( PctPoor18to64*.01*PovUniverse18_64); %applycpr(PctPoorOver65) PoorOver65=round( PctPoorOver65*.01*PovUniverseOver65); %applycpr(PctPoorFamily) PoorFamily=round( PovUniverseFamily*.01*PctPoorFamily); *<----povuniverse variable here may be missing temporarily--; %applycpr(PctPoorUnrelated) PoorUnrelated=round(PctPoorUnrelated*.01*PovUniverseUnrelated); %***dodist(PovRatio,UnderHalf v5tov75 v75to1 1to2) ;*** rest not available in 2k census... 2to3 Over3,PovUniverse); *--NOT full dist; %acprpct(PovRatioUnderHalf,PovUniverse) %acprpct(PovRatiov5tov75,PovUniverse) %acprpct(PovRatiov75to1,PovUniverse) %acprpct(PovRatio1to2,PovUniverse) PovRatioOver2=0; PovRatioOver2=PovUniverse - sum(of PovRatio:); MeanPovRatio= (PovRatioUnderHalf*0.25 + PovRatiov5tov75*0.675 + PovRatiov75to1*0.875 + PovRatio1to2*1.5 + PovRatioOver2*3.0) / PovUniverse; %acprpct(LaborForce,Over16); ***LaborForce=PctLaborForce*.01*Over16; %acprPct(CivLabForce,Over16) ***CivLabForce=PctCivLabForce*.01*Over16; %acprPct(EmployedCLF,CivLabForce) UnemployedCLF=CivLabForce-EmployedCLF; PctUnemployedCLF=100*UnemployedCLF/CivLabForce; %acprPct(Military,Over16) NOTinLF=Over16 - Military - CivLabForce; PctNOTinLF=100*NOTinLF/Over16; %acprPct(LaborForceFemales,Over16Females) %acprPct(CivLabForceFemales,Over16Females) %acprPct(EmployedFemales,CivLabForceFemales) %applycpr(OwnKidsUnder6) %acprPct(OwnKidsOver6AllPrntsWork,OwnKidsOver6) %applycpr(Worker16) %acprPct(Commuters,Worker16) %acprPct(DriveAlone,Worker16) %acprPct(Carpool,Worker16) %acprPct(PublicTrans,Worker16) %acprPct(WalktoWork,Worker16) %acprPct(OtherCommute,Worker16) %acprPct(WorkAtHome,Worker16) %applycpr(AvgCommute) %acprPct(ManProfOccs,EmployedCLF) %acprPct(ServiceOccs,EmployedCLF) %acprPct(SalesOffOccs,EmployedCLF) %acprPct(FarmFishOccs,EmployedCLF) %acprPct(ConsOccs,EmployedCLF) %acprPct(TransOccs,EmployedCLF) %acprPct(Agriculture,EmployedCLF) %acprPct(Construction,EmployedCLF) %acprPct(Manufacturing,EmployedCLF) %acprPct(WholesaleTrade,EmployedCLF) %acprPct(RetailTrade,EmployedCLF) %acprPct(Transportation,EmployedCLF) %acprPct(Information,EmployedCLF) %acprPct(Finance_Ins,EmployedCLF) %acprPct(Professional,EmployedCLF) %acprPct(Educ_Health_SocSvcs,EmployedCLF) %acprPct(RecreationEtc,EmployedCLF) %acprPct(OtherIndustries,EmployedCLF) %acprPct(PublicAdmin,EmployedCLF) %acprPct(PrivWageWorkers ,EmployedCLF) %acprPct(GovWorkers ,EmployedCLF) %acprPct(SelfEmpWorkers ,EmployedCLF) %acprPct(UnpaidFamWorkers ,EmployedCLF) *-------------------------------Social----------------------------------------; Families=FamHHs; PctFamilies=PctFamHHs; %acprPct(FamsWithKids, TotHHs) %acprPct(MarriedCouples, TotHHs) %acprPct(CouplesWithKids, TotHHs) %acprPct(SingleMaleFamilies, TotHHs) %acprPct(SingleFathers, TotHHs) %acprPct(SingleFemaleFamilies, TotHHs) %acprPct(SingleMothers, TotHHs) %acprPct(NonFamHHs, TotHHs) %acprPct(LivingAlone, TotHHs) %acprPct(Over65Alone, TotHHs) %acprPct(FamsWithKids, TotHHs) %acprPct(HHsWithKids, TotHHs) %applycpr(AvgHHSize,round=%str(.1)) %applycpr(AvgFamSize,round=%str(.1)) %acprPct(HHpop,Totpop) %acprPct(FamHHPop,Totpop) NonFamHHPop=Totpop - FamHHPop; PctNonFamHHpop=100*FamHHPop/Totpop; %acprPct(GrpQuarters,TotPop) Householder=TotHHs; PctHouseholder=100*TotPop; %acprPct(Spouse, HHpop) %acprPct(OtherRelative, HHpop) %acprPct(NonRelative,HHpop) %acprPct(UnmarriedPartner, HHpop) UMPartnerHHsPerK=1000*UnmarriedParter/TotHHs; %acprPct(NeverMarried,Over15) %acprPct(Married,Over15) %acprPct(Separated,Over15) %acprPct(Widowed,Over15) %acprPct(Divorced,Over15) %acprPct(InNursery,Over3) %acprPct(InKindergarten,Over3) %acprPct(InElementary,Over3) %acprPct(InHighSchool,Over3) %acprPct(InCollege,Over3) %acprPct(LessThan9th, Over25) %acprPct(SomeHighSchool, Over25) %acprPct(HighSchool, Over25) %acprPct(SomeCollege, Over25) %acprPct(Associates, Over25) %acprPct(Bachelors, Over25) %acprPct(GradProf, Over25) %acprPct(HighSchoolOrMore,Over25) %acprPct(ArmedForces, Over18) %acprPct(Civilian, Over18) %acprPct(Veteran, Over18) %applycpr(disabledUniv5) %acprPct(Disabled, DisableUniv5) %acprPct(Disabled, DisableUniv5) %applycpr(DisabledUniv5_15) %acprPct(Disabled5_15, DisabledUniv5_15) %applycpr(DisabledUniv65) %acprPct(DisabledElder, DisabledUniv65) %applycpr(DisabledUniv16_64) %acprPct(Disabled16_64, DisabledUniv16_64) %acprPct(UsNative, Totpop) %acprPct(BornInUS,Totpop) %acprPct(BornInCurrState, Totpop) %acprPct(BornInDiffState, Totpop) %acprPct(ForeignBorn, Totpop) %acprPct(Naturalized, Totpop) %acprPct(NonCitizen, Totpop) %acprPct(BornInDiffState, Totpop) %acprPct(FBMinusSea, Totpop) %acprPct(FBEurope, FBMinusSea) %acprPct(FBAfrica, FBMinusSea) %acprPct(FBOceania, FBMinusSea) %acprPct(FBLatinAmerica, FBMinusSea) %acprPct(FBEurope, FBMinusSea) %acprPct(FBNorthAmerica, FBMinusSea) %acprPct(EnglishOnly, Over5) %acprPct(OthLang, Over5) %acprPct(OthLangEnglishLTD, Over5) %acprPct(Spanish, Over5) %acprPct(SpanishEnglishLTD, Over5) *---------------------Housing-----------------------------*; %acprPct(OwnerOcc, TotHUs) %acprPct(RenterOcc, TotHUs) %acprPct(PersonsInOwnerUnits,TotPop) %acprPct(PersonsInRenterUnits,TotPop) %applycpr(AvgOwnerHHSize) %applycpr(AvgRenterHHSize) %acprPct(VacHUs,TotHUs) %acprPct(VacantForSale,vachus) %acprPct(VacantForRent,vachus) %acprPct(VacantSeasonal,vachus) TotalOwnerUnits=RenterOcc+VacantForRent; OwnerVacRate=100*VacantForSale/TotalOwnerUnits; TotalRentalUnits=RenterOcc+VacantForRent; RenterVacRate=100*VacantForRent/TotalOwnerUnits; %alias(MobileHomes,UnitsMH) %alias(BoatRV,UnitsRV) %dodist(units,1Detached 1Attached 2 3_4 5_9 10_19 20up MH RV, TotHUs) Units1=Units1Attached + Units1Detached; PctUnits1=100*Units1/TotHUs; %alias(NoVehicles,Vehicles0) %dodist(Vehicles,0 1 2 GE3,OccHus) %dodist(HHF,UtilGas LPGas Electric Kerosene Coal Wood Solar Other NoFuel,OccHUs) %acprPct(NoPlumbing,OccHUs) %acprPct(NoKitchen,OccHUs) %acprPct(NoPhone,OccHUs) %applycpr(PersonsPerRoomLow) %applycpr(PersonsPerRoomMedium) %applycpr(PersonsPerRoomHigh) %dodist(Hval,Under50 50 100 150 200 300 500 OverMillion,OwnerOcc) *<----Not exactly, we have "specified" units in 2k--; %applycpr(MedianHValue) %applycpr(AvgHValue) %acprPct(HUsMort,OwnerOcc) %acprPct(HUsMortOver30Pct,OwnerOcc) %applycpr(MedianOwnerCostsMort) %acprPct(HUsNoMort,OwnerOcc) %acprPct(HUsNoMortOver30Pct,OwnerOcc) %applycpr(MedianOwnerCostsNoMort) %acprPct(NOCashRenter,RenterOcc) %applycpr(MedianGrossRent) %applycpr(AvgGrossRent) %acprPct(CashRenterOver30Pct,RenterOcc) %acprPct(CashRenterOver750,RenterOcc) drop obs_p2x -- whenrun_c2x; drop geocomp_name--PlaceFP sdelm--CBSAyr; run; options ls=160 ps=80 nodate; proc print data=&syslast; by years sumlev puma5; run;