x cd /pub/data/georef/Tools; %let pgm=tract_master14; filename pgm "&pgm..sas"; *---We are creating this setup using the puma_master14 setup as our template. Same idea. --; *---This setup creates the georef.tract_master14 dataset based on geographic reference data from the mable14 database, as revised in fall, 2015. It also (might some day but NOT NOW!) includes data from the most recently available ACS data (2014 5-year). The rows/observations in these datasets correspond to the latest tract codes (officially called 2010 but not always as published in the 2010 census (sic!) Upon further review we see that these are the original 2010 tracts used to publish sf1 data. (6-17-17) ***See tract_master_16temp.sas where we create an alternate version where we do use the latest tracts as per 2015 vintage ACS*** jgb, May, 2016. ---*; libname georef '/pub/data/georef'; libname trctmstr '/pub/data/georef/trctmstr'; %libname (mable14); %libname (mable14); %libname (sf12010x); %let acsvintage=2014; %let acsyear1=%eval(&acsvintage-4); %let year=&acsvintage; %let acsyears=%str(&acsyear1.-&acsvintage); /*<=========================Comment out===================================== %libname(acs&acsvintage,opts=); libname acs (acs&acsvintage); ===========================End commented out================================ */ libname corrlst '/pub/data/corrlst' access=readonly; options fmtsearch=(mable14 mable14 work sasctlgs); *<=====; libname user '/SAS_temp/user'; filename attrib "&pgm..attribs.sas"; title "Creating georef.&pgm with Vintage &acsvintage ACS Estimates Data"; options compress=NO; %macro doit(state,stab); %let ustab=%upcase(&stab); %*--This code to special process New England ----; %if %index(CT ME MA NH RI VT,&ustab) %then %do; %*--it is in New England--; %let nectavars=necta nectadiv cnecta; %let nectatyps=nec necdiv cnec ; %end; %else %do; %let nectavars=; %let nectatyps= ; %end; proc sort data=mable14.&stab.v(keep=tract ZCTA5 County14 County puma12 CouSubFP PlaceFP pop10 intptLat intptLon LandSQMI ur ua cd113 sdbest14 tract cnty state &nectavars CBSA Metdiv cbsatype csa PopGrowthFactor ) out=sortedcodes(compress=NO); by county14 tract; run; data geocodes(compress=NO); set sortedcodes; length gtype $6 geocode $5; array geocodes(*) Cousubfp placefp ur ua cd113 sdbest14 zcta5 &nectavars cbsa metdiv csa cbsatype; retain _gtypes "mcd pla ur ua cd sd zcta &nectatyps cbsa metdiv csa cbsat "; pop14=pop10*PopGrowthFactor; *---This was the county pop estimate in 2014 over the 2010 census pop for county.---; do _i=1 to dim(geocodes); geocode=geocodes{_i}; gtype=scan(_gtypes,_i); output; end; keep state county puma12 tract gtype geocode pop10 pop14; rename puma12=PUMA; run; proc sort; by tract gtype geocode; run; %corrwt(setin=geocodes,setout=&stab.corrwt,g1=state county tract gtype,g2=geocode,idvars=puma,wtvar=pop14,keepwt=0); proc sort; by state county tract gtype descending afact; proc print data=&stab.corrwt (obs=100); title2 "&stab.corrwt"; run cancel; data &stab.data; set &stab.corrwt; by state county tract gtype ; length AreaName $64; if first.tract then do; **length _arg $7; **_arg=state||tract; **PumaName=put(_arg,$tract.); AreaName="Tract "||tract||", "||trim(put(county,$county.)) || " &ustab"; end; retain; *<====NOTE===; length PlaceFP PlaceFP2 $5 CouSubFP CouSubFP2 $5 cd113 cd113_2 $2 sdbest14 sdbest14_2 zcta zcta2 $5 necta nectaDiv $5 Cnecta $3 cbsa $5 MetDiv $5 csa $3 CBSAType $5 ; array geos(*) PlaceFP -- CBSAType; if first.tract then do; do i=1 to dim(geos); geos(i)=' '; end; ***array pcts(*) pctnecta pctnectdiv pcttract2k: *--do we need to set these to missing?---; PctUrban=0; end; if first.gtype then _ng=1; else _ng+1; if _ng >2 then goto cklast; select(gtype); %macro _dum; *<=========; when('cou') do; if _ng=1 then do; County=geocode; pctcnty=100*afact; pctcnty2=.; end; else do; County2=Geocode; pctcnty2=100*afact; end; end; when('co2') do; if _ng=1 then do; cnty2k=geocode; pctcnty2k=100*afact; end; end; when('tract2k') do; if _ng=1 then do; tract2k=geocode; pcttract2k=100*afact; pcttract2k2=.; end; if _ng=2 then do; tract2k2=geocode; pcttract2k2=100*afact; end; end; *when('tract') do; * if _ng=1 then do; *tract=geocode; *pcttract=100*afact; *end; * end; %mend _dum; when('ur') do; if geocode='U' then PctUrban=100*afact; else pcturban=100*(1-afact); end; when('mcd') do; if _ng=1 then do; cousubfp=geocode; pctcousub=100*afact; PctCousub2=.; end; if _ng=2 then do; cousubfp2=geocode; pctcousub2=100*afact; end; end; when('pla') do; if _ng=1 then do; placefp=geocode; pctplace=100*afact; pctplace2=.; end; else do; placefp2=geocode; pctplace2=100*afact; end; end; when('ua ') do; if _ng=1 then do; ua=geocode; pctua=100*afact; end; if _ng=2 and ua=' ' then do; ua=geocode; pctua=100*afact; end; *<---special case: we report the non-blank Urbanized Area code even if it is not the largest--; end; when('cd ') do; if _ng=1 then do; cd113=geocode; pctcd113=100*afact; PctCD113_2=.; end; else do; cd113_2=geocode; Pctcd113_2=100*afact; end; end; when('sd ') do; if _ng=1 then do; sdbest14=geocode; pctsdbest14=100*afact; PctSdbest14_2=.; end; else do; sdbest14_2=geocode; Pctsdbest14_2=100*afact; end; end; when('zcta') do; if _ng=1 then do; zcta=geocode; pctzcta=100*afact; PctZCTA2=.; end; else if _ng=2 then do; zcta2=geocode; pctzcta2=100*afact; end; end; when('nec') do; if _ng=1 then do; necta=geocode; pctnecta=100*afact; end; end; when('necdiv') do; if _ng=1 then do; nectadiv=geocode; pctnectadiv=100*afact; end; end; when('cnec') do; if _ng=1 then do; cnecta=geocode; pctcnecta=100*afact; end; end; when('cbsa') do; if _ng=1 then do; cbsa=geocode; pctcbsa=100*afact; end; end; when('csa') do; if _ng=1 then do; csa=geocode; pctcsa=100*afact; end; end; when('metdiv') do; if _ng=1 then do; metdiv=geocode; pctmetdiv=100*afact; end; end; when('cbsat') do; if _ng=1 then do; cbsatype=geocode; pctcbsatype=100*afact; end; end; **otherwise ; end; *---select (gtype)---; cklast: if last.tract then do; Fipco=county; length PlaceName $7; if PlaceFP ne '99999' then PlaceName=state||PlaceFP; else PlaceName=' '; CBSAName=cbsa; MetDivName=MetDiv; CSAName=csa; NectaName=necta; *---replace this code that requires accessing mable14/mable14 format codes with storing actual names--; length UAName $96 PumaName $80 SchoolName $7; UAName=put(ua,$uauc.); length _arg $7; _arg=state||puma; PUMAName=put(_arg,$puma.); if sdbest14 ne ' ' then SchoolName=state||sdbest14; else SchoolName=' '; length ZCTAName $80; ZCTAName=put(zcta,$zipname.); %local i prefix pfxs; %let pfxs=MetDiv CSA UA Place Necta; %let i=1; %let prefix=%scan(&pfxs,&i); %do %until(&prefix eq %str()); if &prefix.Name=:'99999' then &prefix.Name=' '; %let i=%eval(&i+1); %let prefix=%scan(&pfxs,&i); %end; length UAtype $2; if ua=' ' then UAType=' '; else do; _uaname=put(ua,$uauc.); if index(_uaname,'Urbaniz') then uatype='UA'; else uatype='UC'; *--urban cluster or urbanized area?--; end; format County $county. PlaceName $place. CBSAName $cbsa15_. SchoolName $school. nectaname $necta. MetDivname $metrodiv. csaname $csa.; format Pct: 5.1; output; end; drop gtype geocode afact i _: ; run; %macro acsdata; *---"macro out" this step---; data &stab.acsdata; %let geovars=%str(); **let geovars=IntPtLat IntPtlon Landsqmi Areasqmi; %*--We pick up the geovars and totpop10 from the sf12010x data set as part of the merge step, below--; set acs&acsvintage..ustracts5yr(keep=esriid state County Tract TotPop MedianAge pctUnder18 pctOver65 pctwhite1 pctblack1 pctasian1 pctHispanicPop TotHHs MedianHHInc FamHHs MedianFamInc PovUniverse PctPoor pctGrpQuarters pctBachelorsormore pctInCollege pctForeignBorn TotHUs OccHUs pctRenterOcc MedianHValue MedianGrossRent Where=(state="&state" ) ); ACSYears="&acsyears"; Period="5"; rename TotPop=TotPopACS; label TotPop="Total Pop ACS &acsyears Period Est"; run ; *<===============================NOTE=======================================; %mend acsdata; data trctmstr.&stab.tracts(label="&statenm Tract Master Reference" sortedby=state county tract compress=no ); %include attrib/NOsource2; *<======================We edited this module quite a bit. Use to control variables kept and order-; ***Decided NOT to merge these data--: &stab.acsdata(in=inacs) -----------; merge &stab.data (in=in1) sf12010x.&stab.selectedinv(in=insf1 keep=sumlev state County tract IntPtLat IntPtLon areaSQMI LandSQMI TotPop rename=(TotPop=TotPop10) where=(sumlev='140')) ; by state county tract; esriid=county||compress(tract,'.'); stab="&ustab"; if first.state then do; length _divreg $2 Div Reg $1; _divreg=put(state,$stdivr.); Div=substr(_divreg,1,1); Reg=substr(_divreg,2,1); retain Reg Div; end; label Reg='Census Region' div='Census Division'; if div ne '1' then do; *---set all New England specific items to missing for states outside NE (Div 1)--; necta=' '; nectaname=' '; nectadiv=' '; cnecta=' '; pctnecta=.; pctnectadiv=.; end; if not (in1 and insf1) then do; * and inacs *; put '**Not on all datasets: ' state= county= tract= in1= insf1=; * inacs= *; if in1; end; retain appsurl 'https://mcdc.missouri.edu/applications/applinks/links.php?g=14000USssccctttttt'; *--worked 12/14 at least--; substr(appsurl,56)=substr(esriid,1,11); format placename $place. cbsaname $cbsa. csaname $csa. ; *----Create the final value of PumaName by chopping off redundant ending such as PUMA: Alabama --; if placefp ne '99999' then do; length _pname $80 ; _pname=put(placename,$place.); %chopwrd(_pname); end; format AreaSQMI LandSQMI 9.2 ; format pct: 5.1; drop _: ; run; %mend doit; options NOmprint; *<====; %**dostates(29,names=1); %**dostates(10,names=1); ***filename attrib clear; ***filename attrib "&pgm..attribs2.sas"; %***genattr(setin=trctmstr.motracts); %*---(optional) generate original template then edit later and include in convert step--; /*<=========================Comment out===================================== %**dostates(72,names=1); *--We do not have data for PR at this time--; %dostates(n=51,msgs=1,names=1) ; ===========================End commented out================================ */ *--------------Create the single us tract_master in the parent (georef) directory----------------------*; %macro setref(state,stab); trctmstr.&stab.tracts %mend setref; data georef.tract_master(label="&acsvintage vintage Census Tract Master for U.S." compress=yes index=(state)); set %dostates(n=51,mac=setref) open=defer; run; %**metahtml(filetype=georef,setin=motracts,specific=0, subdir=trctmstr, keywords=tract 2010 master geographic characteristics urban rural metro city county demographics acs data, replace=0) ; run; options nofmterr; data ten; set georef.tract_master (obs=10); run; proc printto print='../tract_master.sampletracts.txt' new; run; proc fsbrowse data=ten printall; run;