x cd /pub/data/acs2011/Tools; %let pgm=ustabs5yr_basetbls; filename pgm "&pgm..sas"; *---Create the new and improved base tables data sets for many different geo levels. Merges data created by Glenn R. in the revised_basetbls temp subdirectory with the selected allgeos data set. A key is to specify shorter variables, with lengths of 5 instead of 8 bytes. Modeled after the bg5yr_basetbls setup which does the same for BGs. jgb, 4-16-13. Reran the uszcta5 tables to fix problem with blank zcta5 vars 6-24-13. ---*; libname btabsR '/pub/data/acs2011/revised_basetbls' ; libname btabs5yr '/pub/data/acs2011/btabs5yr'; libname btabs '/pub/data/acs2011/basetbls'; %libname(acs2011); libname user '/SAS_temp/userb'; options compress=binary; %macro geofltr; *where state in ('29'); %mend geofltr; * libname sasctlgs clear; * libname sasctlgs '/pub/sas/catalogs'; %*** include '/pub/sas/formats/Szipname.sas'; run; 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','e'); *--the corresponding MOE variable uses lower case m instead of e. So for estimate b00001e1 we have the corr moe as m00001m1 . --; macname="moes"||tgrp; call symput(macname,trim(moes)); run; %macro dogeo(setname,sumlev,lvlname,idvars=,tgroups=00_07 08 09_16 17_20 21_24 25_27,geocomps=0,lenesriid=12,viewsonly=0); %if &setname=zctas %then %let zctas=1; %else %let zctas=0; %if &viewsonly %then %goto tgloop; data &setname.ids(compress=no); set acs2011.allgeos2007_2011(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 state geoid; ** logrecno; run; %tgloop: %let ng=1; %let tgroup=%scan(&tgroups,1); %do %until (&tgroup=%str()); %if &viewsonly %then %goto doviews; 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 Pstate 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 ) btabsR.ustabs&tgroup.5yr(in=inests keep=_character_ &&vars&tgroup ) btabsR.ustabs&tgroup.5yr_moes(in=inmoes keep=_character_ &&moes&tgroup ); by state geoid; *** logrecno; 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; %*---inserting this code 6-24-13 after discovering that the zcta5 variables was blank (!!) on the 860 summary records on the allgeos2007-2011 data set. We need to go back and fix that but this will suffice for now.--; if zcta5=' ' then zcta5=esriid; *---custom code for 860 level zcta summaries---; pstate=put(zcta5,$zipstab2.); areaname=put(zcta5,$zipname.); %*--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; index create &indxvar; quit; %doviews: proc sql; create view btabs5yr.mo&setname&tgroup(label="MO subset of ustabs&tgroup") as select * from us&setname.&tgroup %if &zctas %then %str(where pstate='MO'); %else %str( where state='29' ); ; quit; %let ng=%eval(&ng+1); %let tgroup=%scan(&tgroups,&ng); %end; %mend dogeo; options mprint; /* ========================begin comment==================================== %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(places,155 160,%str(Place),idvars=placefp county fipco cbsa metdiv cbsayr, geocomps=0,lenesriid=10,viewsonly=0); *=================Discovered that the MO zcta views were all failing because state variable not defined at the 860 (complete ZCTA across states!) level. So rerunning in late Aug, 2013 to fix.========; %dogeo(zctas,860,%str(ZCTA),idvars=zcta5, geocomps=0,lenesriid=5,viewsonly=1); ==========================end comment====================================== */ %dogeo(pumas,795,%str(PUMAs 2K),idvars=state puma5,geocomps=0,lenesriid=7,viewsonly=0) ods html file="&pgm..html" ; %contdir(btabs5yr,dsn=btabs5yr); run; ods html close;