x cd /pub/data/acs2014/Tools; %let pgm=ustabs5yr_basetbls; filename pgm "&pgm..sas"; *---Must first run gen_tablevars job to generate the btabs5yrmeta sets used in this setup.----; *---Create the enhanced base tables data sets for many different geo levels. Merges original table data created by Glenn R(now in the basetbls5yr 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. See related module bgtract5yr_basetables to create comparable datasets at the tract and bg levels. jgb, 12-9-15. Running again after all input sets sorted by GR 12-12-15. ---*; libname btabsin '/pub/data/acs2014/basetbls5yr' ; libname btabs5yr '/pub/data/acs2014/btabs5yr'; libname btabs '/pub/data/acs2014/basetbls'; %libname(acs2014); %let allgeos=allgeos2010_2014; *===========================================EDIT this set name============================; ****New for 2014 cycle: Some of the input data sets on btabsin are not sorted by state and logrecno as required for our merge step. So we will be defining indexes to allow us to access them in the required order. **** ; /*<=========================Comment out===================================== proc datasets library=btabsin nolist; modify ustabs17_20; index create strecno=(state logrecno) /unique; modify ustabs17_20_moes; index create strecno=(state logrecno) /unique; modify ustabs21_24; index create strecno=(state logrecno) /unique; modify ustabs21_24_moes; index create strecno=(state logrecno) /unique; quit; ===========================End commented out================================ */ libname user '/SAS_temp/userb'; %let ei=i; *<---new for 2014 cycle, me parametrize the choice of letter used to indicate estimate vars. ; %let sfx5yr=; *--sometimes the value should be 5yr . But this year GR left off the 5yr suffix so this takes care of it--; options compress=binary; %macro geofltr; ***where state in ('29'); %mend geofltr; title "&pgm..sas run for 2014 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 acs2014.&allgeos.(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.&sfx5yr(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.&sfx5yr._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-; merge &setname.ids(in=ingeos ) %if &zctas %then %do; zctasorted(in=inests) zctasorted_moes(in=inmoes) %end; %else %do; btabsin.ustabs&tgroup.&sfx5yr(in=inests keep=_character_ &&vars&tgroup ) btabsin.ustabs&tgroup.&sfx5yr._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; /*<=========================Comment out===================================== %dogeo(stcnty,040 050,%str(State and County),idvars=county fipco cbsa metdiv cbsayr, geocomps=0,lenesriid=5,viewsonly=0); %dogeo(cousubs,060,%str(County Subdivision),idvars=county fipco cbsa metdiv cbsayr cousubfp, geocomps=0,lenesriid=10,viewsonly=0); ===========================End commented out================================ */ %dogeo(zctas,860,%str(ZCTA),idvars=zcta5, geocomps=0,lenesriid=5,viewsonly=0); %dogeo(places,155 160,%str(Place),idvars=placefp county fipco cbsa metdiv cbsayr, geocomps=0,lenesriid=10,viewsonly=0); %dogeo(pumas,795,%str(PUMAs),idvars=state puma,geocomps=0,lenesriid=7,viewsonly=0) %dogeo(schoolsuni,970,%str(Unified School District),idvars=state sduni,geocomps=0,lenesriid=7,viewsonly=0) %dogeo(schoolssec,960,%str(Secondary School District),idvars=state sdsec,geocomps=0,lenesriid=7,viewsonly=0) %dogeo(schoolselm,950,%str(Elementary School District),idvars=state sdelm,geocomps=0,lenesriid=7,viewsonly=0) ods html file="&pgm..html" ; %contdir(btabs5yr,dsn=btabs5yr,views=0); run; ods html close;