x cd /pub/data/acs2016/Tools; %let pgm=bgtract5yr_basetbls; filename pgm "&pgm..sas"; *---Creates the block group AND census tract level base tables data sets. Merges data created by Glenn R. in the btabsin temp subdirectory with the selected allgeos data set. A key is to specify shorter variables, with lengths of 4 instead of 8 bytes. jgb, 12-134-16. ---*; %let allgeos=allgeos2012_2016; *<============================EDIT=================================; %include '/pub/sas/autoexec.sas'; libname btabsin '/pub/data/acs2016/base_tables_5yr' ; *<---from Glenn R circa 12/10/15--; libname btabs5yr '/pub/data/acs2016/base_tables_5yr'; libname btabs '/pub/data/acs2016/base_tables_5yr'; %libname(acs2016); %let ei=i; *<---new for 2016 cycle, me parameterize the choice of letter used to indicate estimate vars. ; %let sfx5yr=; *<--last cycle value would have been 5yr --; options compress=binary; %macro geofltr; *---Additional georgraphic filter. ---; **where state in ('10','11'); %*--Delaware and DC for test. Use same filter in step to create ids set above.--; %mend geofltr; %macro dogeo(bgtract); %*--single parm must have value of bg or tract --; data call_symputs(compress=no); %local bg metaset; %if &bgtract=bg %then %let bg=bg; %else %let bg=%str(); %*--macro processes tracts or bgs based on the parm--; %if &bgtract=bg %then %let metaset=bgvarsmeta; %else %let metaset=btabs5yrmeta; %*--for tracts--; set btabs.&metaset; put / _all_; *<==================temp========; if lowcase(tgrp)='085yr' then tgrp='08'; macname="&bgtract.vars"||tgrp; call symput(macname,trim(&bg.vars)); put macname= &bg.vars=; *<===============temp diagnostic==; &bgtract.moes=translate(&bg.vars,"m","&ei"); *--the corresponding MOE variable uses lower case m instead of i/e. So for estimate b00001i1 we have the corr moe as m00001m1 . --; macname="&bgtract.moes"||tgrp; call symput(macname,trim(&bgtract.moes)); run; %let idvars=SumLev AreaName esriid state stab LogRecno County Logrecno CBSA cbsayr metdiv; data trbgids(compress=no); set acs2016.&allgeos. (keep=&idvars rename=(logrecno=logrecnoN)); *<===; %if &bgtract=bg %then %str( where sumlev='150'; ); %else %str( where sumlev='140'; ); %geofltr ; 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_28); %let ng=1; %let tgroup=%scan(&tgroups,1); %do %until (&tgroup=%str()); data btabs5yr.us&bgtract.s&tgroup(label="U.S. &bgtract level data for topic group &tgroup"); if 0 then set trbgids; *--to force these id variables to be first---; length Tract $7 BG $1; %local bgtrvars bgtrmoes; %if &bgtract=tract %then %do; length &&tractvars&tgroup &&tractmoes&tgroup 4; *<-----controls length and order of these variables-; %let bgtrvars=&&tractvars&tgroup; %let bgtrmoes=&&tractmoes&tgroup; %end; %else %do; length &&bgvars&tgroup &&bgmoes&tgroup 4; *<-----controls length and order of these variables-; %let bgtrvars=&&bgvars&tgroup; %let bgtrmoes=&&bgmoes&tgroup; %end; merge trbgids(in=ingeos keep=&idvars ) btabsin.us&bgtract.s&tgroup.&sfx5yr(in=inests keep=_character_ &bgtrvars ) btabsin.us&bgtract.s&tgroup.&sfx5yr._moes(in=inmoes keep=geoid logrecno state &bgtrmoes); by state logrecno; %if &bgtract=bg %then %str( if geoid=:'150'; ); %else %str( if geoid=:'140'; ); %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---; %if &bgtract=bg %then %str( bg=substr(esriid,12,1); ); %else %str(drop bg;); drop sumlevel stusab Name; run; proc datasets nolist library=btabs5yr; modify us&bgtract.s&tgroup; index create state; index create county; quit; proc sql; create view btabs5yr.mo&bgtract.s&tgroup(label="MO subset of us&bgtract.s&tgroup") as select * from us&bgtract.s&tgroup where state='29'; quit; %let ng=%eval(&ng+1); %let tgroup=%scan(&tgroups,&ng); %end; %mend dotabs; options mprint; %dotabs(tgroups=25_28); %mend dogeo; %dogeo(bg); %dogeo(tract); options mprint; %contdir(btabs5yr,dsn=btabs5yr,views=0);