x cd /pub/data/acs/Tools; %let pgm=test_aggmoe_Boone; filename pgm "&pgm..sas"; *---Do test run where we take weighted avgs of MOE values to see if what we get is reasonable-; title "&pgm.: Testing Feasibility of Using agg macro to calculate moes"; %libname(acs2014); libname user '/SAS_temp/user'; libname userb '/SAS_temp/userb'; data aggin userb.&pgm._cntyck; set acs2014.usmcdcprofiles5yr; where state='29' and sumlev in ('040','050','140'); keep state county tract TotPop TotPop_moe age0_4--Over65_moe; drop pct: ; if sumlev='140' then output aggin; else if geocomp<='00' then output userb.&pgm._cntyck; run; %let moes=%varlist(*_moe,aggin); /*<=========================Comment out===================================== data _null_; set aggin; array nvars(*) _numeric_; length moewts $4000; retain moewts; do i=1 to dim(nvars); length _varname _moename $32; _moename=lowcase(vname(nvars(i))); _ix=index(_moename,'_moe'); if _ix then moewts=trim(moewts)||' '||substr(_moename,1,length(_moename)-4); end; call symput('moewts',trim(moewts)); stop; run; %put moewts=&moewts; *---We wound up not needing this variable--------------; ===========================End commented out================================ */ *--replace moes with their squares prior to aggregating. Will then have to take sqrts in post-step--; data aggin2; set aggin; array _moes(*) &moes; do _i=1 to dim(_moes); *--replace the moe values with "relative moe" values, i.e. Moe as a pct of the estimate (moewt)--; _moes(_i) = _moes(_i)**2; end; run; %agg(aggin=aggin2, aggout=userb.aggout, aggby=state county,agglvl=2,grand=1, aggvars=_numeric_, debug=0) ; *** means=&moes, meanwts=&moewts, ; run; data userb.aggout2; set userb.aggout; array _moes(*) &moes; do _i=1 to dim(_moes); *--Take the square root of the sums of the moes--; _moes(_i) = round( sqrt(_moes(_i))); end; drop _i; run; data userb.BooneData; set aggin (in=in1) aggin2 (in=in2) userb.aggout (in=in3) userb.aggout2 (in=in4) userb.&pgm._cntyck (in=in5); where county='29019'; if in1 then set='aggin '; else if in2 then set='aggin2'; else if in3 then set='aggout'; else if in4 then set='aggout2'; else if in5 then set='cntyck '; ***; if set in ('aggout2','cntyck'); drop median: ; run; ods html file="&pgm..html" style=websas; options ls=147; title2 "Boone Data"; proc print data=userb.Boonedata ; by state county; id set; run; ods html close;