x cd /pub/data/popests/Tools; %let pgm=intercensal20xx; filename pgm "&pgm..sas"; *---Read county level revised inter-censal estimates for the US and create popests.usintercensal20xx with radically restructured data for the nation, states and counties. We reshape the data so that the time variable is in the rows. We have 12 rows per geo with 2 census values and estimates for years 2000-2009. jgb, OSEDA, Missouri Census Data Center. Oct. 2011. ---*; %let dpath=%str(/pub/data/popests/intercensal20xx); libname popestsi "&dpath"; *-----We created an alias for this data directory to work within the 8-character limit we use for our datasets metadata. The intercensal20xx subdirectory is also known as intrcnsl (10-3-11) ----; %macro ilz(v); %*---arg specifies a character variable that needs to be right-justified with leading zeroes inserted. So if v=sumlev and it had a value of '40 ' it would be edited to '040'. --; &v=translate(right(&v),'0',' '); %mend ilz; *----We begin by reading the 3 county-level data sets with age-sex, race-hispanic-sex and total-only estimates. We leve these in the same basic format as produced by the Bureau with the time series going across the rows (observations) and with the demographic categories being ID variables Sex, Race, Origin, AgeGrp. ---*; /* ========================begin comment==================================== data popestsi.usstcntytots(label='US State & County Total Pop Revised Inter-censal Estimates 2000-2010'); infile "&dpath/CO-EST00INT-TOT.csv" dsd lrecl=512 firstobs=2 termstr=crlf; length SumLev $3 Region Division $1 State $2 Stab $2 _cnty $3 County $5 _stname $40 Areaname $40 default=5; input SumLev--State _cnty _stname--Areaname EstBase2k PopEst2000-PopEst2009 Pop2010Census PopEst2010 ; %ilz(sumlev) %ilz(state) if _cnty='0' then _cnty=' '; else %ilz(_cnty) ; if _cnty=' ' then County=State; else County=State||_cnty; Stab=put(state,$fipstab.); format EstBase2k PopEst: comma11.; drop _: ; run; proc print data=popestsi.usstcntytots (obs=50); by state; id county Areaname; title2 "&syslast"; run; ==========================end comment====================================== */ *---------------------------Do the sex, race, origin (Hispanic) data----------------------------------------------; data usstcntysexracehisp(label='US State & County Sex, Race, Hispanic Revised Inter-censal Estimates 2000-2010'); infile "&dpath/CO-EST00INT-SEXRACEHISP.csv" dsd lrecl=512 firstobs=2 termstr=crlf; length SumLev $3 State $2 Stab $2 _cnty $3 County $5 _stname $40 Areaname $40 Sex $1 Origin $1 Race $1 default=5; input SumLev--State _cnty _stname--Race EstBase2k PopEst2000-PopEst2009 Pop2010Census PopEst2010 ; %ilz(sumlev) %ilz(state) if _cnty='0' then _cnty=' '; else %ilz(_cnty) ; if _cnty=' ' then County=State; else County=State||_cnty; Stab=put(state,$fipstab.); format EstBase2k PopEst: comma11.; drop _: ; run; proc sort out=aggin1; by state sex race origin; run; *---aggregate data to get state totals to be added to data set---; %agg(setin=aggin1,setout=stots1,aggby=state sex race origin,idvars=stab, aggvars=_numeric_,dropvars=_nag_ _lvl_) data popestsi.usstcntysexracehisp(label='US State & County Sex, Race, Hispanic Revised Inter-censal Estimates 2000-2010'); length SumLev $3 State $2 Stab $2 County $5 Areaname $40 Sex $1 Origin $1 Race $1 default=5; set stots1(in=instate) usstcntysexracehisp ; by state; *--Interleave with state totals first---; if instate then do; County=State; Areaname=put(state,$state.); SumLev='040'; end; drop _: ; run; proc print data=popestsi.usstcntysexracehisp (obs=70); by state; id county Areaname; title2 "&syslast"; run; *----------------------------Now do the sex and age data set------------------------------------------*; data usstcntyagesex5yr(label='US State & County 5-year Age and Sex Revised Inter-censal Estimates 2000-2010'); infile "&dpath/CO-EST00INT-AGESEX-5YR.csv" dsd lrecl=512 firstobs=2 termstr=crlf; length SumLev $3 State $2 Stab $2 _cnty $3 County $5 _stname $40 Areaname $40 Sex $1 AgeGrp $2 default=5; input SumLev--State _cnty _stname--AgeGrp EstBase2k PopEst2000-PopEst2009 Pop2010Census PopEst2010 ; %ilz(sumlev) %ilz(state) %ilz(AgeGrp) if _cnty='0' then _cnty=' '; else %ilz(_cnty) ; if _cnty=' ' then County=State; else County=State||_cnty; Stab=put(state,$fipstab.); format EstBase2k PopEst: comma11.; drop _: ; run; proc sort out=aggin2; by state sex agegrp ; run; *---aggregate data to get state totals to be added to data set---; %agg(setin=aggin2,setout=stots2,aggby=state sex agegrp,idvars=stab, aggvars=_numeric_,dropvars=_nag_ _lvl_) data popestsi.usstcntyagesex5yr(label='US State & County 5-year Age and Sex Revised Inter-censal Estimates 2000-2010'); length SumLev $3 State $2 Stab $2 County $5 Areaname $40 Sex $1 AgeGrp $2 default=5; set stots2(in=instate) usstcntyagesex5yr ; by state; *--Interleave with state totals first---; if instate then do; County=State; Areaname=put(state,$state.); SumLev='040'; end; drop _: ; run; proc print data=popestsi.usstcntyagesex5yr (obs=70); by state; id county Areaname; title2 "&syslast"; run;