x cd /pub/data/acs/Tools; %let pgm=aggacsmoes_problem; filename pgm "&pgm..sas"; *---we generate aggregates to Boone county from tract level data and generate a report showing problems with the calculated moe s vs the published county moe s--; libname acs2009 '/pub/data/acs2009'; libname user '/SAS_temp/user'; data &pgm._aggin &pgm._cnty; set acs2009.usmcdcprofiles5yr (keep=state sumlev age: county); where sumlev in ('140','050') and state='29' and county='29019'; if sumlev='140' then output &pgm._aggin; else output &pgm._cnty; run; data aggbytract; set &pgm._aggin end=last; array agedata(12,2) age0_4--age75_84_moe; array sumsqmoe(12) _temporary_; array sumsest(12) _temporary_; do i=1 to 12; moe=agedata(i,2); est=agedata(i,1); sumsqmoe(i) + moe**2; sumsest(i) + est; end; if last then do; do i=1 to 12; agedata(i,1)=sumsest(i); agedata(i,2)=sqrt(sumsqmoe(i)); end; output; put _all_; end; keep county sumlev age0_4--age75_84_moe; run; %genrenam(aggbytract,xvars=county sumlev,sfx=agg); data combined; merge &pgm._cnty(in=inco) aggbytract(in=inagg &rename); by county; run; %let cohorts=0_4 5_9 10_14 15_19 20_24 25_34 35_44 45_54 55_59 60_64 65_74 75_84; data &pgm._report; length variable $8 estimate estimateAgg MOE_cnty MOE_aggformula Relative_MOE_cnty Relative_MOE_agg MOE_ratio 8; format Relative_MOE: 6.1 MOE_ratio 5.1; set combined; %macro docohorts; %do i=1 %to 12; %let cohort=%scan(&cohorts,&i); Variable="Age&cohort"; estimate=Age&cohort; estimateAgg=Age&cohort.agg; MOE_cnty=age&cohort._moe; MOE_aggformula=age&cohort._moeagg; Relative_MOE_cnty=100*MOE_cnty/estimate; Relative_MOE_agg=100*MOE_aggformula/estimate; MOE_ratio=MOE_aggformula/MOE_cnty; output; %end; %mend docohorts; %docohorts keep variable-- MOE_ratio; run; ods html file="&pgm..html"; proc print data=&pgm._report; id variable; title "Comparing MOE Values for Age Table: County Totals vs. Tract Aggregations"; title2 "Tract Aggregations Done by Using Formula Provided: SQRT of the Sum of MOEs Squared (for tracts)"; footnote "From acs/Tools/&pgm..sas on &sysdate "; run; ods html close;