x cd /pub/data/saipe/Tools; %let pgm=cnvt_stcnty_20xx; filename pgm "&pgm..sas"; *---Starting with 2010 conversion run (2008 data) we change things so that only the new year(s) data is read. Then we append the new data to recreate the 20xx dataset. This requires 2 manual (interactive from SAS DM) actions: 1. Prior to running this setup, rename the saipe.usstcnty20xx dataset to usstcnty20xxB (for backup). ==================================================================!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!====================== Then run this setup which will create a new dataset for just the current year or years. It will also append those datasets to the old one (stored in the B dataset) and write a new usstcnty20xx set. 2. After all is verified to be OK the backup dataset should be deleted - including its index. ----; %let lastyear=2004; *<==============================running 11-30-2005=======; %let lastyear=2005; *<==============================running 01-14-2008=======; %let lastyear=2007; *<==============================running 12-15-2008 with new data for 2006 and 2007 =======; %let lastyear=2008; *<==============================running 03-31-2009 with new data for 2008 and revised logic =======; %let lastyear=2009; *<==============================running 12-11-2010 with new data for 2009 =======; %let lastyear=2010; *<==============================running 11-30-2011 with new data for 2010 =======; %let lastyear=2011; *<==============================running 12-24-2012 with new data for 2011 =======; %let lastyear=2012; *<==============================running 01-23-2014 with new data for 2012 =======; %let lastyear=2013; *<==============================running 12-17-2014 with new data for 2013 =======; %let lastyear=2014; *<==============================running 12-09-2015 with new data for 2014 =======; %let lastyear=2015; *<==============================running 12-15-2016 with new data for 2015 =======; %let lastyr=%substr(&lastyear,3,2); libname saipe '/pub/data/saipe'; filename stcnty "/pub/data/saipe/est&lastyr.ALL.txt"; options mprint; title "SAIPE conversion run - &pgm for Post-2000 Poverty and Income Estimates"; data saipe.usstcnty&lastyear (label="SAIPE Inc and Poverty Ests &lastyear" sortedby=year state county); infile stcnty lrecl=264; length Year $4 SumLev $3 State $2 Stab $2 County $5 Geocode $5 Areaname $45; length Poor 5 PctPoor 4 Poor0_17 5 PctPoor0_17 4 PoorRelChild5_17 5 PctPoorRelChild5_17 MedianHHInc 4 CIWPoor CIWPctPoor CIWPoor0_17 CIWPctPoor0_17 CIWPoorRelChild5_17 CIWPctPoorRelChild5_17 4 CIWMedianHHInc 4; length PoorUnder5 5 PctPoorUnder5 4 CIWPoorUnder5 CIWPctPoorUnder5 4; input _state $char2. +1 _cnty $char3. Poor 8-15 _poor1 17-24 _poor2 26-33 PctPoor 35-38 _pctpoor1 40-43 _pctpoor2 45-48 Poor0_17 50-57 _poor0_171 59-66 _poor0_172 68-75 PctPoor0_17 77-80 _pctpoor0_171 82-85 _pctpoor0_172 87-90 PoorRelChild5_17 92-99 _poorRelChild5_171 101-108 _poorRelChild5_172 110-117 PctPoorRelChild5_17 119-122 _pctpoorRelChild5_171 124-127 _pctpoorRelChild5_172 129-132 MedianHHInc 134-139 _MedianHHInc1 141-146 _MedianHHInc2 148-153 @; if _cnty eq ' 0' then do; *--These data only available for the US and states (NOT counties)---*; input PoorUnder5 155-161 _poorunder51 163-169 _poorunder52 171-177 PctPoorUnder5 179-182 _Pctpoorunder51 184-187 _pctpoorunder52 189-192 @; end; input Areaname $194-238 Stab $240-241 _Yr $246-247 ReleaseDate $256-264; Year='20'||_yr; if _state in (' 0','00') then do; SumLev='010'; State='00'; Geocode=State; County=' '; end; else if _cnty=' 0' then do; Sumlev='040'; State=translate(_state,'0',' '); Geocode=State; County=' '; end; else do; SumLev='050'; County=_state||_cnty; State=translate(_state,'0',' '); County=translate(County,'0',' '); Geocode=County; end; *-----Convert the confidence intervals to interval width variables instead-----; %macro ci(v,l); %let var=&v; label &var="&l" ; %do _j=1 %to 2; _w1=&var - _&var.1 ; _w2=_&var.2 - &var; if (&var le 100 and abs(_w1 - _w2) gt 1.1) or (&var gt 100 and abs(_w1 - _w2) gt 1) and "&var" ne "MedianHHInc" then do; _nbad+1; if _nbad le 40 then put / &var= _w1= _w2= _&var.1= _&var.2= _all_ ; else abort abend; end; CIW&var=_w1; label CIW&var="Conf Intvl width for &var"; if _w1 ne _w2 then CIW&var=(_w1 + _w2) * .5; *<=== for unbalanced intervals about median hh income===; %if &v=MedianHHInc %then %let _j=2; %else %let var=Pct&v; %end; %if &v ne MedianHHInc %then %do; if Pct&v then Univ&v=round(100*&v/Pct&v); label Pct&v="Pct &l" Univ&v="Poverty Universe for &v"; %end; %mend ci; %ci(Poor,Total Poor Persons) %ci(Poor0_17,%str(Poor aged 0-17)) %ci(PoorRelChild5_17,%str(Poor related children 5-17 in families)) %ci(MedianHHInc,Median Household Income) if sumlev ne '050' then do; %ci(PoorUnder5,Poor Under Age 5) end; format Pct: CIWPct: 5.1; format MedianHHInc dollar8.; label Year='Income Year' SumLev='Geog. Summary Level'; drop _: ; return; run; proc sql; create table saipe.mostcnty&lastyear as select * from saipe.usstcnty&lastyear where state='29'; quit; data saipe.usstcnty20xx(label="SAIPE Inc and Poverty Ests 2000-&lastyear" index=(year) sortedby=year state county); *---We forgot to do the rename before running so the 20xxB set was last years and did not include the 2014 data---; set saipe.usstcnty20xxB /* saipe.usstcnty2014 */ saipe.usstcnty&lastyear ; *---could use proc append here, I suppose---; run; proc datasets library=saipe nolist; modify usstcnty20xx; index create state; index create yearst=(year state); index create county; quit; proc tabulate data=saipe.usstcnty20xx(drop=CIW:); title2 'Tabulate Report on Poverty Rates and Counts in saipe.usstcnty20xx'; title3 '**Caution: The means on the county level data are not weighted so they are NOT state values!'; class year sumlev state; format state $fipstab. sumlev $sumlev.; var poor poor0_17 pctpoor pctpoor0_17; table SumLev,(state all)*year, (pctpoor pctpoor0_17)*mean*f=5.1 (Poor Poor0_17)*sum*f=comma12.; run;