x cd /pub/data/acs2012/Tools; %let pgm=ustabs5yr_basetbls; filename pgm "&pgm..sas"; *******************Problem with geocodes on the output sets for 2012 vintage runs. E.g. county was 3-characters instead of 5. Next cycle change the order in which the data sets are merged, with the ids set coming last so those values are what gets stored!!!!! **********************************************************************************************************; ***********ALSO check for Name variable $1000 (???) *********; *---Must first run gen_tablevars job to generate the btabs5yrmeta sets used in this setup.----; *---See also the companion modules tr5yr_basetbls and bg5yr_basetbls which create comparate data sets for those 2 smaller units--; *---Create the enhanced base tables data sets for many different geo levels. Merges original table data created by Glenn R. in the original_btabs5yr subdirectory with the latest 5yr allgeos data set. A key is to specify shorter variables, with lengths of 5 instead of 8 bytes. See separate comparable setups that do the same for tracts and bgs. We merge the estimates and moes into single datasets containing both. jgb, 12-31-13. ---*; libname btabsin '/pub/data/acs2012/original_btabs5yr' ; libname btabs5yr '/pub/data/acs2012/btabs5yr'; libname btabs '/pub/data/acs2012/basetbls'; %libname(acs2012); libname user '/SAS_temp/userb'; %let ei=i; *<---new for 2012 cycle, me parametrize the choice of letter used to indicate estimate vars. ; options compress=binary; %macro geofltr; ***where state in ('29'); %mend geofltr; title "&pgm..sas run for 2012 vintage 5-year ACS base tables geo-specific data sets"; *<=====; data call_symputs(compress=no); set btabs.btabs5yrmeta; if lowcase(tgrp)='085yr' then tgrp='08'; macname="vars"||tgrp; call symput(macname,trim(vars)); moes=translate(vars,"m","&ei"); *--the corresponding MOE variable uses lower case m instead of i or e. So for estimate b0000111 we have the corr moe as m00001m1 . --; macname="moes"||tgrp; call symput(macname,trim(moes)); run; %***put _global_; %macro dogeo(setname,sumlev,lvlname,idvars=,tgroups=00_07 08 09_16 17_20 21_24 25_27,geocomps=0,lenesriid=12,viewsonly=0); %local zctas byvars; %if &setname=zctas %then %let zctas=1; %else %let zctas=0; %if &zctas %then %let byvars=geoid; %else %let byvars=state geoid; %if &viewsonly %then %goto tgloop; data &setname.ids(compress=no); set acs2012.allgeos2008_2012(keep=sumlev geoid geocomp AreaName logrecno state stab &idvars rename=(logrecno=logrecnoN)); %if %length(&sumlev)=3 %then %do; where sumlev ="&sumlev"; %end; %else %do; retain _sumlev "&sumlev"; if index(_sumlev,sumlev) > 0; %end; length Logrecno $7; Logrecno=put(logrecnon,z7.); drop logrecnoN; drop _: ; run; proc sort; by &byvars; ** state geoid; ** logrecno; run; %tgloop: %let ng=1; %let tgroup=%scan(&tgroups,1); %do %until (&tgroup=%str()); %if &viewsonly %then %goto doviews; %if &zctas %then %do; %*---for these we use a special view of the input data sets because they are not sorted by geoid as required--; data zctas&tgroup/view=zctas&tgroup; set btabsin.ustabs&tgroup.5yr(keep=geoid &&vars&tgroup); where geoid=:'860'; run; proc sort data=zctas&tgroup out=zctasorted; by geoid; run; data zctas&tgroup._moes/view=zctas&tgroup._moes; set btabsin.ustabs&tgroup.5yr_moes(keep=geoid &&moes&tgroup); where geoid=:'860'; run; proc sort data=zctas&tgroup._moes out=zctasorted_moes; by geoid; run; %end; data btabs5yr.us&setname.&tgroup(label="U.S. &lvlname level data for topic group &tgroup"); if 0 then set &setname.ids; *--to force these id variables to be first---; %if &geocomps %then %do; length Geocomp $2 GeocompName $80; %end; %if &zctas %then %do; attrib State length=$2 label='Primary State'; %end; length esriid $&lenesriid; length &&vars&tgroup &&moes&tgroup 5; *<-----controls length and order of these variables-; **************************************NEXT TIME switch order so that the values in ids get kept, NOT the orginal from GR***; merge &setname.ids(in=ingeos ) %if &zctas %then %do; zctasorted(in=inests) zctasorted_moes(in=inmoes); %end; %else %do; btabsin.ustabs&tgroup.5yr(in=inests keep=_character_ &&vars&tgroup ) btabsin.ustabs&tgroup.5yr_moes(in=inmoes keep=_character_ &&moes&tgroup ); %end; by &byvars; where ( substr(geoid,1,3) in (%qlist(&sumlev)) ) ; *** and ( substr(geoid,8,3) > '009' ); %geofltr; esriid=substr(geoid,8,&lenesriid); drop geoid; %if &geocomps %then %do; Geocomp=substr(geoid,4,2); GeocompName=put(geocomp,$geocomp.); if geocomp ne '00'; keep geocomp geocompName; %end; %else %do; drop geocomp; if substr(geoid,4,2) ne '00' then delete; %end; **format county $5.; if not (ingeos and inests and inmoes) then do; _nerr+1; if _nerr le 20 then put / "**missing data** " _n_= ingeos= inests= inmoes= state= logrecno= geoid=; else abort abend; drop _nerr; end; %if &zctas %then %do; ***if zcta5=' ' then zcta5=esriid; *--We had a problem with the geos data set in 2011 cycle which made this necessary; *---custom code for 860 level zcta summaries---; pstate=put(zcta5,$zipstab2.); Stab=pstate; State=put(pstate,$stabfip2.); areaname=put(zcta5,$zipname.); drop sumlevel stusab Name; %*--we have PR zctas at the end that are out of sort order so we need to avoid going past the last non-PR obs-; output; ****** if zcta5='99929' then stop; %end; run; proc datasets nolist library=btabs5yr; modify us&setname.&tgroup; %**if &zctas %then %let indxvar=pstate; %**else %let indxvar=state; %let indxvar=state; index create &indxvar; quit; %doviews: proc sql; create view btabs5yr.mo&setname&tgroup(label="MO subset of us&setname&tgroup") as select * from us&setname.&tgroup where state='29'; quit; %let ng=%eval(&ng+1); %let tgroup=%scan(&tgroups,&ng); %end; %mend dogeo; options mprint; %dogeo(stcnty,040 050,%str(State and County),idvars=county fipco cbsa metdiv cbsayr, geocomps=0,lenesriid=5,vieswonly=0); %dogeo(cousubs,060,%str(County Subdivision),idvars=county fipco cbsa metdiv cbsayr cousubfp, geocomps=0,lenesriid=10,vieswonly=0); %dogeo(zctas,860,%str(ZCTA),idvars=zcta5, geocomps=0,lenesriid=5,vieswonly=0); %dogeo(places,155 160,%str(Place),idvars=placefp county fipco cbsa metdiv cbsayr, geocomps=0,lenesriid=10,vieswonly=0); %dogeo(pumas,795,%str(PUMAs),idvars=state puma5,geocomps=0,lenesriid=7,viewsonly=0) ods html file="&pgm..html" ; %contdir(btabs5yr,dsn=btabs5yr); run; ods html close;