x cd /pub/data/acs2006/Tools; %let pgm=wormcan2; filename pgm "&pgm..sas"; *---Continue the "Can of Worms" processing. wormcan1 module dealt with latest estimates. In this module we focus on 2000 census data at the county and PUMA levels and try to estimate latest data using latest PUMA data. jgb, 8-11-2008. ----*; *<=======================Change all occurrences of acs2006 to the appropriate filetype per year==================; %let debug=1; %let libout=temp; %let year=2006; *<---the data year. Correspongs to the data directory we submit from (e.g. acs2006/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 "acs2006/Tools/&pgm : Estimate ACS data for smaller counties for &year"; libname user '/SAS_temp/user'; libname temp '/pub/data/acs2006/temp'; %libname(acs2006); %libname(sf32000x); libname corrlst '/pub/data/corrlst'; %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 acs2006.allgeos where state="&state" and sumlev='050'; select name into :moevars separated by ' ' from profilevars where name contains 'MOE'; quit; %***put &moevars; /* =======================Begin comment================ *---Use utility macro to generate the rename code to be used in subsequent data step to append a sfx to all numeric vars-; %genrenam(sf32000x.usstcnty,xvars=state county sumlev,sfx=_c2x) data cnty2k; set sf32000x.usstcnty ( &rename where=(state="&state" and sumlev="050" and index("&bigcos",county)=0) ); drop age: pctage: over: under: ; run; data temp.&stab.cos2kests(label="2k census county data with _c2x varname suffixes + &yr estimates" ); merge cnty2k(in=in2kdata) temp.&stab.estimates&yr(in=inests) corrlst.&stab.cnty_puma(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(sf32000x.uspumas,xvars=state puma5,sfx=_p2x) data temp.&stab.pumas2k(label="2k census PUMA data with _p2x varname suffixes" ); set sf32000x.uspumas ( &rename where=(state="&state" ) ); drop age: pctage: over: under: ; run; proc sort; by puma5; run; data pumapros_nomoes; length puma5 $5; set acs2006.usmcdcprofiles ( 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.pumasacs&yr(label="ACS&yr. PUMA data with _pacs varname suffixes" Index=(puma5)); set pumapros_nomoes ( &rename); drop sumlev age: pctage: over: under: ; run; data temp.hannibal(label='Sample work dataset'); *----------------temporary test----------------------*; merge temp.&stab.pumas2k (in=inpuma2k) temp.&stab.pumasacs&yr(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='00400' then output; run; ======================End comment================== */ 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; data &libout..hannibal_counties(label='Test of wormcan project'); length County $5 ; if 0 then set acs2006.usmcdcprofiles (drop=&moevars); set temp.hannibal; areaname=areaname_c2x; if &debug then put / areaname=; retain debug &debug; *---The order in which we define the variables is driven by attempt to estimate variables per their order in the acs profiles report. However, in many cases we shall need to estimate some other variable first, the value of which we can then use to estimate our current "target" variable. For example, our first variable to be estimated is really TotHHs. But to estimate it we first estimate the PctOccupied item and we apply this fraction to the latest TotHUs estimate to get the TotHHs estimate.--; %acsest(PctOccupied,round=.00001,acsvar=PctOccHUs) TotHUs=huest_&year; *<---should have renamed it in wormcan1 step but for now this will fix it.--; TotHHs= round(TotHUs*.01*PctOccHUs); if &debug then put TotHHs=; _checksum=0; _checksum2=0; _checksum3=0; %macro dohhinc; %global debug; %local hhincsfxs i _pctvar; %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(&hhincsfxs,&i); %if &pass=1 %then %do; %let _pctvar=PctHHInc&sfx; %acsest(&_pctvar,round=.00001) HHInc&sfx=.01*&_pctvar*TotHHs; _checksum + HHInc&sfx; %end; %else %do; %if &i=1 %then %str( _rake=TotHHs/_checksum; ); PctHHInc&sfx=PctHHInc&sfx*_rake; HHInc&sfx=HHInc&sfx*_rake; _checksum2 + HHInc&sfx; _checksum3 + PctHHInc&sfx; %end; %end; if &debug and &pass=2 then put _checksum= _checksum2= _checksum3= _rake= TotHHs=; if round(_checksum3) ne 100 then do; put '***_checksum3 for PctHHINCxxx values does not add to 100 as expected *** ' _checksum3= ; end; %end; %*--do pass loop--; %mend dohhinc; options mprint; %dohhinc ; %acsest(MedianHHInc) %acsest(AvgHHInc) *-----------Skipping, for now, reset of Table5 (dp3_2k) with various number of HHs with income and avg such income by type--; PctFamHHs_pacs=100*FamHHs_pacs/TotHHs_pacs; *<----it was not defined on the dataset, but this is what it should have been--; *---Start with PctFamilies vs PctFamHHs---; %acsest(PctFamilies,acsvar=PctFamHHs); %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; *--We cannot do a family income distribution table because it was not part of our 2k data. Maybe later----; %*dodist(FamHHInc,%str(0 10 15 25 35 50 75 100 150 200),FamHHs); %acsest(MedianFamInc) %acsest(AvgFamInc) %acsest(PCI) NonFamHHs=TotHHs-FamHHs; keep county sumlev -- areaname TotPop -- PctCashRenterOver750; run;