x cd /home/riceg/ACS_SAS_processing; %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 base_tables_5yr subdirectory with the selected allgeos data set. A key is to specify shorter variables, with lengths of 4 instead of 8 bytes. Requirements: bgvarsmeta and btabs5yrmeta datasets in user lib (created by gen_tablevars program) */ %include '/pub/sas/autoexec.sas'; libname btabs '/pub/data/acs2017/base_tables_5yr'; libname acs2017 '/pub/data/acs2017'; libname user '/home/riceg/ACS_SAS_processing/temp'; libname out '/pub/data/acs2017/base_tables_5yr'; %let allgeos=allgeos2013_2017; *<============================ EDIT; %let ei=i; *-- New for 2016 cycle, we parameterize the choice of letter used to indicate estimate vars. ; %let sfx5yr=; *-- Last cycle value would have been 5yr. ; options compress=binary; *-- Additional geographic filter: ; %macro geofltr; *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 user.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 user.&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 acs2017.&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 out.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) btabs.us&bgtract.s&tgroup.&sfx5yr(in=inests keep=_character_ &bgtrvars) btabs.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=out; modify us&bgtract.s&tgroup; index create state; index create county; quit; proc sql; create view out.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; %dotabs; %mend dogeo; %dogeo(bg); %dogeo(tract); ods html file="&pgm..html" ; %contdir(out,dsn=out,views=0); run; ods html close; %include sascode(notify);