x cd /pub/data/acs2007/Tools; %let pgm=applycpr3yr_template; filename pgm "&pgm..sas"; *---This is the starter file for coders to create versions of applying the County/PUMA Ratio method to estimate ACS data for smaller Missouri counties. 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. Plan is to have 2 job created from this template: applycpr_bce and applycpr_jgb that will produce 2 output data sets that will need to be compared to insure a consistent methodology. ----*; %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 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; proc contents data=acs2006.usmcdcprofiles(keep=_numeric_) noprint out=profilevars(keep=name); run; %global bigcos; proc sql noprint; select county 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; *---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.mocounties,xvars=state county sumlev,sfx=_c2x) data cnty2k; set sf32kacs.mocounties ( &rename where=(state="&state" and sumlev="050" and index("&bigcos",county)=0) ); run; data temp.&stab.cos2kests(label="2k census county data with _c2x varname suffixes + &yr estimates" ); merge sf32kacs.&stab.counties(in=in2kdata) cprdata.&stab.estimates3yr(in=inests) cprdata.&stab.cnty_puma&yr(in=inclist); by county; 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.&stab.pumas,xvars=state puma5,sfx=_p2x) data temp.&stab.pumas2k(label="2k census PUMA data with _p2x varname suffixes" ); set sf32kacs.&stab.pumas ( &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.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; %macro acsest(var,round=1,acsvar= ); %if %lowcase(%substr(&var,1,3))=%str(pct) and &round=1 %then %let round=.00001; %*--different rounding for percentages--; %if %nrbquote(&acsvar) eq %str() %then %let acsvar=&var; 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 &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 &debug %then %do; put '***debug: ' _cpr = &var._c2x= &var._p2x= &acsvar._pacs= &acsvar=; %end; %mend acsest; %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 count with tabtot as the denominator--; %global debug; %local i _pctvar sfx nsfxs; %let nsfxs=%lenlst(&sfxs); %*let hhincsfxs=0 10 15 25 35 50 75 100 150 200; %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 10; %let sfx=%scan(&sfxs,&i); %if &pass=1 %then %do; %let _pctvar=Pct&tabnm&sfx; %acsest(&_pctvar,round=.00001) &tabnm&sfx=.01*&_pctvar*&tabtot; _checksum + &tabnm&sfx; %end; %else %do; %if &i=1 %then %str( _rake=&tabtot/_checksum; ); Pct&tabnm&sfx=Pct&tabnm&sfx*_rake; &tabnm&sfx=&tabnm&sfx*_rake; _checksum2 + &tabnm&sfx; _checksum3 + Pct&tabnm&sfx; %end; %end; if &debug and &pass=2 then put "For table &tabnm : " _checksum= _checksum2= _checksum3= _rake= TotHHs=; if round(_checksum3) ne 100 then do; put "***_checksum3 for Pct&tabnm values does not add to 100 as expected *** " _checksum3= ; end; %end; %*--do pass loop--; %mend dodist; *------------------------------Data Step to "apply CPR" method to estimate data for counties for the 3yr period---------;