x cd /pub/data/acs2010/Tools; %let pgm=moilksbgtables; filename pgm "&pgm..sas"; *---Access the block group estimates data as previoulsy stored in the Missouri_Illinpois_Kansas subdirectory of basetbls. We want to create a single dataset per state, with only those tables available at the BG level. Will then do a standard extract to create a bgprofiles version of these data. April 3, 2012: we now have the moe datasets to go with the 5yr bg sets for the 3 states. We process them here as well. J. Blodgett, OSEDA, March, 2012. ---*; libname basetbls '/pub/data/acs2010/basetbls'; libname moilks '/pub/data/acs2010/basetbls/Missouri_Illinois_Kansas' access=readonly; filename tables '/pub/data/acs2010/basetbls/5_year_detailed_tables.csv'; *---Read the CSV file with table level metadata indicating which tables should be available at BG level--; data bgtables; infile tables firstobs=2 dsd termstr=crlf end=last; length TableId $9 TableTitle $80 _note $40 bgflag $1 ; input TableId--bgflag; length keeptabs $2500 droptabs $4000; retain keeptabs droptabs; if index(tableid,'PR') then delete; *<---not keeping these PR only tables for now----; if bgflag='X' or tableid=:'B0000' then keeptabs=trim(keeptabs)||' '||trim(tableid)||'i:'; else if substr(tableid,length(tableid),1)='I' then droptabs=trim(droptabs)||' '||trim(tableid)||'i:'; drop keeptabs droptabs; if last then do; call symput('keeptabs',trim(keeptabs)); call symput('droptabs',trim(droptabs)); length _keepmoes $2500; _keepmoes=substr( tranwrd(keeptabs,'i:','m:'),20); *<--the substr omits 2 B00 tabs-; call symput('keepmoes',_keepmoes); end; drop _: ; run; %put keeptabs=&keeptabs; %put keepmoes=&keepmoes; %put droptabs=&droptabs; %macro doit(state,stab); data basetbls.&stab.bg5yr(label="&statenm block group level tables w 2006-2010 estimates" compress=binary); length Sumlev $3 esriid $12 State Stab $2 County $5 Tract $7 bg $1 geoid $20; merge moilks.ustabs00_075yrbg moilks.ustabs085yrbg moilks.ustabs09_165yrbg moilks.ustabs17_205yrbg moilks.ustabs21_245yrbg moilks.ustabs25_265yrbg ; by geoid; where state="&state"; County=substr(geoid,8,5); Tract=substr(geoid,13,4)||'.'||substr(geoid,17,2); BG=substr(geoid,19,1); Esriid=substr(geoid,8); %include '/pub/data/acs2010/basetbls/Varlabs/bgleveltabs.txt'; *---include the label statements---; keep Sumlev--geoid &keeptabs; drop &droptabs ; format _character_ ; format _numeric_ ; informat _character_ ; run ; *----------Generate a list of tables kept on the bg dataset---; %let tabs1=%varlist(*i1,basetbls.&stab.bg5yr); %put &tabs1; *---Now repeat process for the moe tables---; data basetbls.&stab.bg5yr_moes(label="&statenm block group level MOEs 2006-2010 tables" compress=binary); length State $2 County $5 Tract $7 bg $1 geoid $20; merge moilks.ustabs00_075yrbg_moes moilks.ustabs085yrbg_moes moilks.ustabs09_165yrbg_moes moilks.ustabs17_205yrbg_moes moilks.ustabs21_245yrbg_moes moilks.ustabs25_265yrbg_moes ; by geoid; where state="&state"; County=substr(geoid,8,5); Tract=substr(geoid,13,4)||'.'||substr(geoid,17,2); BG=substr(geoid,19,1); Esriid=substr(geoid,8); %***include '/pub/data/acs2010/basetbls/Varlabs/bgleveltabs.txt'; *---include the label statements---; keep State -- geoid &keepmoes; *** drop &droptabs ; format _character_ ; format _numeric_ ; informat _character_ ; * if _N_ gt 10 then stop; ********; run ; *----------and a list of tables on the bg_moes dataset---; %let moes1=%varlist(*m1,basetbls.&stab.bg5yr_moes); %put &moes1; %mend doit; /* ========================begin comment==================================== %dostates(29,names=1); ==========================end comment====================================== */ %dostates(17 20,names=1)