x cd /pub/data/georef/Tools; %let pgm=tract_master22; filename pgm "&pgm..sas"; /* This program uses puma_master22 as a template. Same idea. It creates the georef.tract_master22 dataset based on geographic reference data from the mable22 database. It also includes data from the most recently available ACS data (2021 5-year). The rows/observations in these datasets correspond to the 2020 tract codes. We are not keeping any MOE (margin of error) estimates for the ACS data on these datasets. */ %let acsvintage = 2021; options nonotes source nomprint spool compress=binary; %include "/pub/sas/autoexec.web.sas"; libname trctmstr '/pub/data/georef/trctmstr'; libname georef '/pub/data/georef'; %libname(mable22); %libname(corrlst); %libname(dhc2020x); %libname(acs&acsvintage,opts=); libname acs (acs&acsvintage); options fmtsearch=(mable22 work sasctlgs); * dev ; * libname user '/pub/data/georef/trctmstr/temp'; filename attrib "&pgm..attribs.sas"; title "Creating georef.&pgm with vintage &acsvintage ACS estimates data"; %let acsyear1 = %eval(&acsvintage - 4); %let year = &acsvintage; %let acsyears = %str(&acsyear1.-&acsvintage); %macro doit(state,stab); %let ustab = %upcase(&stab); %if %index(CT ME MA NH RI VT,&ustab) %then %do; * New England ; %let nectavars = necta nectadiv cnecta; %let nectatyps = nec necdiv cnec ; %end; %else %do; %let nectavars = ; %let nectatyps = ; %end; proc sort data=mable22.&stab.v (keep=tract ZCTA County CouSub20 Place pop20 intptLat intptLon LandSQMI ur ua cd118 puma22 state &nectavars CBSA20 Metdiv20 cbsatype20 csa20 sdbest20) out=sortedcodes; by county tract; run; data geocodes; set sortedcodes; length gtype $6 geocode $5; array geocodes(*) county Cousub20 place ur ua cd118 zcta &nectavars cbsa20 metdiv20 csa20 cbsatype20 sdbest20; retain _gtypes "cou mcd pla ur ua cd zcta &nectatyps cbsa metdiv csa cbsat sd"; do _i = 1 to dim(geocodes); geocode = geocodes{_i}; gtype = scan(_gtypes, _i); output; end; keep state county puma22 tract gtype geocode pop20; rename puma22 = PUMA; run; proc sort; by tract gtype geocode; run; %corrwt( setin=geocodes, setout=&stab.corrwt, g1=state county tract gtype, g2=geocode, wtvar=pop20, idvars=puma, keepwt=0 ); proc sort; by state county tract gtype descending afact; run; data &stab.data; set &stab.corrwt; by state county tract gtype ; if first.tract then do; TractName = "Tract "||trim(tract)||", "||trim(put(county, $county.)); end; retain; length Place Place2 CouSub CouSub2 $5 cd118 cd118_2 $2 sdbest sdbest2 zcta zcta2 necta nectaDiv $5 Cnecta $3 cbsa MetDiv $5 csa $3 CBSAType $5 ; if first.tract then do; array geos(*) Place -- CBSAType; do i = 1 to dim(geos); geos(i) = ' '; end; PctUrban = 0; end; if first.gtype then _ng = 1; else _ng+1; if _ng > 2 then goto cklast; select(gtype); when('cou') County = geocode; when('tract') tract = geocode; when('ur') do; if geocode = 'U' then PctUrban = 100 * afact; else pcturban = 100 * (1 - afact); end; when('mcd') do; if _ng = 1 then do; cousub = geocode; pctcousub = 100 * afact; pctcousub2 = .; end; if _ng = 2 then do; cousub2 = geocode; pctcousub2 = 100 * afact; end; end; when('pla') do; if _ng = 1 then do; place = geocode; pctplace = 100 * afact; pctplace2 = .; end; else do; place2 = 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 Urban Area code even if it is not the largest. ; end; when('cd ') do; if _ng = 1 then do; cd118 = geocode; pctcd118 = 100 * afact; end; else cd118_2 = geocode; end; when('sd ') do; if _ng = 1 then do; sdbest = geocode; pctsdbest = 100 * afact; PctSdbest2 = .; end; else do; sdbest2 = geocode; Pctsdbest2 = 100 * afact; end; end; when('zcta') do; if _ng = 1 then do; zcta = geocode; pctzcta = 100 * afact; pctzcta2 = 1.; end; else if _ng = 2 then do; zcta2 = geocode; pctzcta2 = 100 * afact; end; end; when('nec') necta = geocode; when('necdiv') nectadiv = geocode; when('cnec') cnecta = geocode; when('cbsa') cbsa = geocode; when('csa') csa = geocode; when('metdiv') metdiv = geocode; when('cbsat') cbsatype = geocode; *otherwise ; end; * of [select (gtype)] ; cklast: if last.tract then do; Fipco = county; *FipCo2 = County2; if Place ne '99999' then PlaceName = put(state||Place, $place20_.); else PlaceName = ' '; CBSAName = put(cbsa, $cbsa20_.); MetDivName = put(MetDiv, $metdiv20_.); CSAName = put(csa, $csa21_.); NectaName = put(necta, $necta21_.); UAName = put(ua, $urban22_.); PumaName = put(state||puma, $puma22_.); ZCTAName = put(zcta, $ZIPNAME12_.); if sdbest ne ' ' then SchoolName = put(state||sdbest, $school20_.); else SchoolName = ' '; %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; format Pct: 5.1; output; end; drop gtype geocode afact i _: ; run; data &stab.acsdata; set acs.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 population, ACS &acsyears 5-year estimate"; run; data trctmstr.&stab.tracts(label="&statenm tract master reference" sortedby=state county tract); %include attrib/NOsource2; merge &stab.data (in=in1) &stab.acsdata(in=inacs) dhc2020x.&stab.selectedinv(in=indhc keep=sumlev state County tract IntPtLat IntPtLon areaSQMI LandSQMI TotPop rename=(TotPop=TotPop20) 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 = .; end; if not (in1 and inacs and indhc) then do; putlog 'WARNING: Not on all datasets: ' state= county= tract= in1= inacs=; if in1; end; retain appsurl 'https://mcdc.missouri.edu/applications/applinks/links.php?g=14000US29019001002'; substr(appsurl, 68) = esriid; *putlog 'NOTE: ' appsurl= ; format AreaSQMI LandSQMI 9.2 ; format pct: 5.1; drop _: ; run; %mend doit; /* ======================== Comment out ==================================== %dostates(09, names=1); %dostates(10, names=1); %dostates(72, names=1); %* We do not have data for PR at this time. ; =========================== End commented out =============================== */ %dostates(n=52,msgs=1,names=1) ; %macro setref(state, stab); trctmstr.&stab.tracts %mend setref; data georef.tract_master_2020(label="&year vintage census tract master for U.S." index=(state)); set %dostates(n=52,mac=setref) open=defer; run;