x cd /pub/data/saipe/Tools; %let pgm=agg_sahie_cbsas; filename pgm "&pgm..sas"; *---Aggregate the health insurance estimates data to various geographic levels including: U.S. totals CBSAs (metro, micro and non-cbsas remainders of states). Also, derive data for the 0-17 age cohort by subtraction of agecat values. Key aspect here is to aggregate the moes so we have them for the aggregated results. jgb, OSEDA under contract with the Missouri Census Data Center. Oct. 2008 ---*; libname saipe '/pub/data/saipe'; libname georef '/pub/data/georef' access=readonly; libname user '/SAS_temp/userb'; proc format; value $agecat 0='Under 65' 1='18 to 64' 5='Under 18'; run; data sahiestates sahiecounties; set saipe.sahie05; where agecat in ('0','1') and racecat='0' and sexcat='0' and iprcat='0'; where also state le '06'; *<==================teseting===========================; by state county; array _save (7) _pop _nic _nui _pctelig _nic_moe _nui_moe _pctelig_moe; retain _pop -- _pctelig_moe; array _current(7) pop nic nui pctelig nic_moe nui_moe pctelig_moe ; array moe2(3) nic_moe2 nui_moe2 pctelig_moe2; if agecat='0' then do _ivar=1 to 7; _save{_ivar}=_current{_ivar}; end; link outproc; if agecat='1' then do; do _ivar=1 to 7; if _ivar le 3 then _current{_ivar}=_save{_ivar} - _current{_ivar}; *--this is the value for 0-17 age category. We subtract the current value (for 18-64 cohort) from the save 0-64 cohort figures--; else if _ivar=4 then pctelig= 100*nui/pop; *--We use the formula for calculating the moe of the difference of 2 moes--; if _ivar ge 5 then _current{_ivar}=1.645*sqrt( (_save{_ivar}/1.645)**2 + (_current{_ivar}/1.645)**2 ); end; agecat='5'; link outproc; end; return; outproc: do i=1 to 3; moe2{i}=(_current{i+4}/1.645)**2; end; if sumlev='040' then output sahiestates; else output sahiecounties; return; drop _: i nic_moe nui_moe pctelig_moe; run; *----Aggregate the state summaries to get state and US totals including the new 0-17 age cohort values-----; proc summary data=sahiestates; class state agecat; var pop nic nui pctelig nic_moe2 nui_moe2 pctelig_moe2; id year; types agecat agecat*state; output out=sahiesums1 sum= ; run; %***agg(aggin=sahiestates,aggout=stateage,aggby=state agecat,aggvars= pop nic nui pctelig nic_moe2 nui_moe2 pctelig_moe2,naggvars=7, means=pctelig,meanwts=pop,idvars=year,dropvars=_lvl_ _nage_); *---post-process to complete moe calcs---; data stateage2; set sahiesums1; retain sumlev '040'; array moe2 (3) nic_moe2 nui_moe2 pctelig_moe2; array moe (3) nic_moe nui_moe pctelig_moe ; if state=' ' then sumlev='010'; else sumlev='040'; do i=1 to 3; moe{i}=round( 1.645*sqrt( moe2{i}), .1 ); end; pctelig=100*nui/pop; format pctelig 4.1; drop nic_moe2 nui_moe2 pctelig_moe2 i; drop _: ; format pop nic nui comma11.; run; proc sort out=saipe.ussahie_states05(label='Uninsured by state & US Tots with some age detail for 2005'); by sumlev state agecat; run; proc print data = saipe.ussahie_states05; format state $fipstab. agecat $agecat.; title2 'saipe.ussahie_states05 data set'; run; run;