x cd /pub/data/acs2007/Tools; %let pgm=agg_cpr_hlspts; filename pgm "&pgm..sas"; *---Aggregate both 2000 census (sf32kacs) and 2007 3yr data (acs2007) to get "HLSPT"=High Level Suppressed Portion Totals . This is data that summarizes the areas that have no ACS data for the period and which we shall therefore be using when we apply our CPR (county-PUMA ratio) methodology. Instead of looking at ratios of county and PUMA we shall look at ratios of counties and the portion of the PUMA which has no data. This should provide significantly improved guesstimates. jgb, Feb, 2009 ----*; %include "cprmacros.sas"; %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 is 05_07 when year=2007---; %let debug=1; title "&pgm: Aggregate to Higher Level Suppressed Portion Totals"; title2 "Doing Estimates of Small Mo Counties Using &year 3yr Data With HLSPTs"; 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'; select name into :_means separated by ' ' from acs.variables where wtvar ne ' ' and dup=0; select wtvar into :_mweights separated by ' ' from acs.variables where wtvar ne ' ' and dup=0; select name into :_aggvars separated by ' ' from acs.variables where dup=0 ; quit; /* =======================Begin comment================ *----1-time step to add 3 counties to the cnty-puma corr list file: 3 large counties that we did not use before. (But need for doing subtraction when creating hlspt data sets. We have special code to get around this below but want to make that redundant code unnecessary in the future. --; data new3; set sf32kacs.sf3counties(keep=county totpop); select (county); *<====CUSTOM CODE HERE!!! Specify large counties (65k+) that are entirely within a PUMA and not = a PUMA-; when('29021') puma5='00200'; when('29031') puma5='02000'; when('29051') puma5='00500'; otherwise delete; end; fipco=county; pop2k=totpop; size='l'; drop totpop; run; data cprdata.mocnty_puma07(label='Correlation list: Mo county to PUMA 2007 w 3 large cos added'); set cprdata.mocnty_puma07_bkup new3; by county; run; *---create intermediata data sets with PUMA and County level summaries for the state and year/period with MOE vars removed--; data &stab.cntys &stab.pumas (drop=county); set acs.usmcdcprofiles3yr(where=(sumlev in ('050','795') and state='29') drop=&moevars in=inacs); if sumlev='050' then output &stab.cntys; else output &stab.pumas; keep sumlev county areaname puma5 datecreated _numeric_; run; data &stab.cntys2; merge &stab.cntys(in=inacsdata) cprdata.&stab.cnty_puma&yr (in=ingeo); by county; if inacsdata; if not ingeo then do; size='l'; *--thats the letter "l", for "large" as opposed to 'm' or 's'.--; select (county); *<====CUSTOM CODE HERE!!! Specify large counties (65k+) that are entirely within a PUMA and not = a PUMA-; when('29021') puma5='00200'; when('29031') puma5='02000'; when('29051') puma5='00500'; otherwise delete; end; end; run; proc sort; by puma5; run; data agginacs; set &stab.pumas &stab.cntys2; by puma5; if sumlev='795' then wt=1; else if sumlev='050' then wt=-1; else abort abend; run; *** options mprint; %smryvars(setin=agginacs,setout=aggin_stats,vars=&_aggvars,stats=n nmiss sum,classvars=puma5 wt); *--Want a report that tells us how often a variable will have at least 1 missing value within a PUMA group---; proc sort data=aggin_stats (where=(not (varname=:'Pct') and wt=-1) keep=puma5 varname nmiss wt) out=tempsort; by varname puma5; run; data cprdata.missinghlspt_data; set tempsort; by varname; if first.varname then do; array misses(0:5) miss0 miss1-miss5; do i=0 to 5; misses{i}=0; end; end; if nmiss gt 5 then nmiss=5; if nmiss=. then nmiss=1; misses{nmiss}+1; if last.varname then do; ncases=sum(of miss0-miss5); number_with_missing= ncases - miss0; some_missing_flag=(miss0 < ncases); Pct_missing=round( 100*(number_with_missing)/ncases ); output; end; drop i nmiss puma5 wt; drop miss1-miss5; run; proc print ; id varname; var miss0 number_with_missing pct_missing some_missing_flag; title 'Summary Report Indicating by Variable Problems with Missing Data for HLSPT Calculations'; run; proc freq; table some_missing_flag number_with_missing; run; data missing_report; set aggin_stats; where not (Varname=:'Pct') and nmiss; run; proc format; value zeronz 0='zero' other='Non-zero'; run; proc freq data=missing_report; table Varname * wt*nmiss*n /list; title2 'Report Summarizing Missing Values on agginacs data set'; title3 'Pct Variables Not Shown'; run; title2 ; %agg(aggin=agginacs,aggout=cprdata.&stab.hlspt_acs, aggvars=&_aggvars, means=&_means, mweights=&_mweights, idvars=datecreated, dropvars=_lvl_ wt, aggby=puma5, facvar=wt) run; data hlspt1; set cprdata.&stab.hlspt_acs(obs=1); run; proc fsbrowse printall data=hlspt1; title2 "First Obs on the &stab.hlspt_acs data set"; run; *------New steps to create the corresponding "HLSPT" summaries from the 2k census data. We attempt to replicate any missing data so that if a variable for a county is missing on the acs 3yr data then we force it to be missing on the 2k data set as well. This is a little messy, to say the least.------; data temp.cnty2kwpuma; merge sf32kacs.sf3counties cprdata.&stab.cnty_puma&yr (in=ingeo); by county; if sumlev='050'; if not ingeo then do; size='l'; *--thats the letter "l", for "large" as opposed to 'm' or 's'.--; select (county); *<====CUSTOM CODE HERE!!! Specify large counties (65k+) that are entirely within a PUMA and not = a PUMA-; when('29021') puma5='00200'; when('29031') puma5='02000'; when('29051') puma5='00500'; otherwise delete; end; end; run; proc sort; by puma5 county; run; data temp.aggin_pre2k; set sf32kacs.sf3pumas temp.cnty2kwpuma; by puma5; *---interleave----; drop esriid areaname counties places logrecno intPt: stab geocode pop2k fipco; drop PctOver15--PctMoveInBefore1969; *----a whole bunch of variables that are not on the sf32kacs data sets--; run; %genrenam(user.agginacs,xvars=sumlev puma5 county wt areaname logrecno dateCreated fipco size,sfx=_acs) data aggin2k ; merge temp.aggin_pre2k (in=in2k) agginacs ( &rename in=inacs); by puma5 county; if inacs; *--we only keep data for the relevant pumas and counties---; if not in2k then do; put '**** ' puma5= county= " ****Not matched on 2k data set***** aborting run.... " ; abort abend; end; if sumlev='050' then do; *---here is where we check for missing values in the acs data set and make the corresponding variable missing for 2k data--; %macro recode_missing; %let naggvars=%lenlst(&_aggvars); %do i=1 %to &naggvars; %let var=%scan(&_aggvars,&i); if &var._acs=. or &var._acs=.N then &var=.A; %end; drop %do i=1 %to &naggvars; %let var=%scan(&_aggvars,&i); &var._acs %str( ) %end; ; %mend recode_missing; options mprint; *<========================================================================; %recode_missing ; end; run; ======================End comment================== */ options NOmprint; %agg(aggin=aggin2k,aggout=sf32kacs.&stab.hlspt_2k, aggvars=&_aggvars, means=&_means, mweights=&_mweights, dropvars=_lvl_ wt, aggby=puma5, facvar=wt) run; data hlspt2; set cprdata.&stab.hlspt_2k(obs=1); run; proc fsbrowse printall data=hlspt2; title2 "First Obs on the &stab.hlspt_2k data set"; run; *---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'; *---we cannt keep the m size cos & estimate their data for checking purposes with this hlspt--; run; data temp.&stab.cos2kests(label="2k census county data with _c2x varname suffixes + &yr 3yr 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 temp.pumastemp(label='Sample work dataset'); **** was: merge temp.&stab.pumas2k (in=inpuma2k) temp.&stab.pumasacs3yr(in=inpumaacs) temp.&stab.cos2kests(in=incos); 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 output; *** else if puma5='01300' then output; run; options mprint NOmlogic; *------------------------------Data Step to "apply CPR" method to estimate data for counties for the 3yr period---------; data cprdata.SmallCounties(label='3yr estimates for all MO 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 temp.pumastemp; 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; ======================End comment================== */