x cd /pub/data/acs2011/Tools; %let pgm=bg5yr_basetbls; filename pgm "&pgm..sas"; *---Create the new and improved block group level base tables data set. Merges data created by Glenn R. in the revised_basetbls temp subdirectory with the selected allgeos data set. A key is to specify shorter variables, with lengths of 4 instead of 8 bytes. jgb, 4-10-13. ---*; libname btabsR '/pub/data/acs2011/revised_basetbls' ; libname btabs5yr '/pub/data/acs2011/btabs5yr'; libname btabs '/pub/data/acs2011/basetbls'; %libname(acs2011); options compress=binary; %macro geofltr; *here state in ('10','11'); *--Delaware and DC for test. Use same filter in step to create ids set above.--; *where state in ('29'); %mend geofltr; data call_symputs(compress=no); set btabs.bgvarsmeta; if lowcase(tgrp)='085yr' then tgrp='08'; macname="bgvars"||tgrp; call symput(macname,trim(bgvars)); bgmoes=translate(bgvars,'m','e'); *--the corresponding MOE variable uses lower case m instead of e. So for estimate b00001e1 we have the corr moe as m00001m1 . --; macname="bgmoes"||tgrp; call symput(macname,trim(bgmoes)); run; %let idvars=SumLev AreaName esriid state stab LogRecno County Logrecno CBSA cbsayr metdiv; data bgids(compress=no); set acs2011.allgeos2007_2011(keep=&idvars rename=(logrecno=logrecnoN)); %geofltr ; where sumlev='150'; length Logrecno $7; Logrecno=put(logrecnon,z7.); drop logrecnoN; run; proc sort; by state logrecno; run; %macro dotabs(tgroups=00_07 08 09_16 17_20 21_24 25_27); %let ng=1; %let tgroup=%scan(&tgroups,1); %do %until (&tgroup=%str()); data btabs5yr.usbgs&tgroup(label="U.S. block group level data for topic group &tgroup"); if 0 then set bgids; *--to force these id variables to be first---; length Tract $7 BG $1; length &&bgvars&tgroup &&bgmoes&tgroup 4; *<-----controls length and order of these variables-; merge bgids(in=ingeos keep=&idvars ) btabsR.usbgs&tgroup.5yr(in=inests keep=_character_ &&bgvars&tgroup) btabsR.usbgs&tgroup.5yr_moes(in=inmoes keep=_character_ &&bgmoes&tgroup); by state logrecno; %geofltr; length esriid $12; esriid=substr(geoid,8); drop geoid; format county $5.; if not (ingeos and inests and inmoes) then do; _nerr+1; if _nerr le 20 then put / "**missing data** " ingeos= inests= inmoes= state= logrecno= geoid=; else abort abend; drop _nerr; end; tract=substr(esriid,6,4)||'.'||substr(esriid,10,2); *--to get our archive std xxxx.xx format code---; bg=substr(esriid,12,1); run; proc datasets nolist library=btabs5yr; modify usbgs&tgroup; index create state; index create county; quit; proc sql; create view btabs5yr.motracts&tgroup(label="MO subset of ustracts&tgroup") as select * from ustracts&tgroup where state='29'; quit; %let ng=%eval(&ng+1); %let tgroup=%scan(&tgroups,&ng); %end; %mend dotabs; options mprint; %dotabs(tgroups=00_07 08 09_16 17_20 21_24 25_27); %contdir(btabs5yr,dsn=btabs5yr);