%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=2 %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"--; %if %superq(PctOf) = %str() %then %put ****acprPct macro must have a 2nd positional parameter specified ****; %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;