x cd /home/riceg/ACS_SAS_processing; %let pgm=ustabs5yr_basetbls; filename pgm "&pgm..sas"; /* Create the enhanced base tables data sets for many different geo levels. Merges original table data created by Glenn R (now in the base_tables_5yr 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. Must first run gen_tablevars job to generate the btabs5yrmeta sets used in this setup. Must create new directory base_tables_5yr. */ %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; options compress=binary nomprint nosymbolgen nonotes; /*<=========================Comment out===================================== *-- New for 2016 cycle: Some of the input data sets on btabs 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. ; *-- We tried to define these unique indices (2016) but it failed, saying we had duplicate state logrecno combinations. So let's look. ; proc sort data=btabs.ustabs17_20(keep=state logrecno geoid areaname ) out=keys; by state logrecno; run; data _null_ ; set keys; by state logrecno; if not (first.logrecno and last.logrecno); put state $2. +1 logrecno $7. +1 geoid +1 areaname; run; proc datasets library=btabs 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================================ */ %let ei=i; *-- the letter used to precede cell # in variable names. We used e in 2011, i in 2016. ; %let sfx5yr=; *-- sometimes GR uses "5yr" as a suffix in the data set names; %macro geofltr; * where state in ('29'); %mend geofltr; title "&pgm..sas run for 2017 vintage 5-year ACS base tables geo-specific data sets"; data call_symputs(compress=no); set user.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_28,geocomps=0,lenesriid=12,viewsonly=0,noviews=0); %local zctas byvars; %if &setname=zctas %then %let zctas=1; %else %let zctas=0; %if &zctas %then %let byvars=geoid; %else %let byvars=geoid; *-- Before it was state geoid ; %if &viewsonly %then %goto tgloop; data &setname.ids(compress=no); set acs2017.&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 btabs.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 btabs.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 out.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; btabs.ustabs&tgroup.&sfx5yr(in=inests keep=_character_ &&vars&tgroup ) btabs.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); * NO!! drop geoid; %if &geocomps %then %do; Geocomp=substr(geoid,4,2); GeocompName=put(geocomp,$geocomp.); * 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; %if &setname ne regdiv %then %do; proc datasets nolist library=out; modify us&setname.&tgroup; /* %if &zctas %then %let indxvar=pstate; %else %let indxvar=state; */ %let indxvar=state; index create &indxvar; quit; %end; %doviews: %if &noviews=0 and (&setname ne regdiv) %then %do; proc sql; create view out.mo&setname&tgroup(label="MO subset of us&setname&tgroup") as select * from us&setname.&tgroup where state='29'; quit; %end; %let ng=%eval(&ng+1); %let tgroup=%scan(&tgroups,&ng); %end; %mend dogeo; *-- We just specify regdiv as name, but US gets prepended, so we get a usregdiv data set. ; %dogeo(regdiv,010 020 030,%str(US totals Regions and Divs),idvars=region division state,geocomps=1,lenesriid=1,noviews=1); %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); %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,noviews=1) %dogeo(schoolssec,960,%str(Secondary School District),idvars=state sdsec,geocomps=0,lenesriid=7,viewsonly=0,noviews=1) %dogeo(schoolselm,950,%str(Elementary School District),idvars=state sdelm,geocomps=0,lenesriid=7,viewsonly=0,noviews=1) ods html file="&pgm..html" ; %contdir(out,dsn=out,views=0); run; ods html close; /*<=========================Comment out===================================== ===========================End commented out================================ */ %include sascode(notify);