x cd /pub/data/georef/Tools; %let pgm=puma_master22; filename pgm "&pgm..sas"; /* This program creates the georef.puma_master_2020 dataset based on geographic reference data from the mable22 database, as revised October, 2022. It also includes data from the most recently available ACS data (2022 1-year). The rows/observations in these datasets correspond to the latest PUMA codes, officially called 2020. We prefer 2022, because that was the year when they began to be used. Before then, the Bureau was publishing vintage 2021 ACS data using the old 2010 PUMAs. We are not keeping any MOE (margin of error) estimates for the ACS data on these datasets. */ %let acsvintage = 2022; options notes source nomprint spool compress=binary; %include "/pub/sas/autoexec.web.sas"; libname georef '/pub/data/georef'; libname pumamstr '/pub/data/georef/pumamstr'; %libname(mable22); %libname(dhc2020x); %libname(acs&acsvintage,opts=); libname acs (acs&acsvintage); libname corrlst '/pub/data/corrlst' access=readonly; options fmtsearch=(mable22 work sasctlgs); filename attrib "&pgm..attribs.sas"; title "Creating georef.&pgm with vintage &acsvintage ACS estimates data"; %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=puma22 ZCTA County CouSub20 Place pop20 intptLat intptLon LandSQMI ur ua cd118 puma12 state &nectavars CBSA20 Metdiv20 cbsatype20 csa20) out=sortedcodes; by puma22 county; run; data geocodes; set sortedcodes; length gtype $6 geocode $5; array geocodes(*) county Cousub20 place ur ua cd118 puma12 zcta &nectavars cbsa20 metdiv20 csa20 cbsatype20; retain _gtypes "cou mcd pla ur ua cd puma12 zcta &nectatyps cbsa metdiv csa cbsat "; do _i = 1 to dim(geocodes); geocode = geocodes{_i}; gtype = scan(_gtypes, _i); output; end; keep state puma22 gtype geocode pop20; run; proc sort; by puma22 gtype geocode; run; %corrwt( setin=geocodes, setout=&stab.corrwt, g1=state puma22 gtype, g2=geocode, wtvar=pop20, keepwt=0); proc sort; by state puma22 gtype descending afact; run; data &stab.data; set &stab.corrwt; by state puma22 gtype ; * where puma22 ne '99999'; *length pumaName $80; if first.puma22 then do; length _arg $7; _arg = state||puma22; PumaName = put(_arg, $puma.); end; retain; length County County2 Place Place2 $5 CouSub CouSub2 $5 cd118 cd118_2 $2 puma22 zcta $5 necta nectaDiv $5 Cnecta $3 cbsa $5 MetDiv $5 csa $3 CBSAType $5 ; if first.puma22 then do; array geos(*) County -- 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') do; if _ng = 1 then do; County = geocode; pctcnty = 100 * afact; pctcnty2 = .; end; else do; County2 = Geocode; pctcnty2 = 100 * afact; end; end; 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 do; cd118_2 = geocode; end; end; when('puma12') do; if _ng = 1 then do; puma12 = geocode; pctpuma12 = 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; * of [select (gtype)] ; cklast: if last.puma22 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||puma22, $puma22_.); ZCTAName = put(zcta, $ZIPNAME12_.); %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; rename puma22 = PUMA; * important for merge later on ; end; drop gtype geocode afact i _: ; run; proc print data=&syslast; title2 "&syslast"; by state; id zcta; run cancel; data &stab.acsdata; set acs.usmcdcprofiles(keep=geoid state SumLev 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" and sumlev='795' ) ); puma = substr(geoid, 12, 5); * ACS geoids got longer in 2022 with addition of geographic variant. ; drop geoid; ACSYears = "&acsvintage"; Period = "1"; rename TotPop = TotPopACS; label TotPop = "Total population, ACS &acsvintage 1-year estimate"; run; data pumamstr.&stab.pumas(label="&statenm PUMA Master Reference" sortedby=state puma); %include attrib/NOsource2; merge &stab.data (in=in1) &stab.acsdata(in=inacs) dhc2020x.&stab.cdsldspumas(in=indhc keep=sumlev state puma22 IntPtLat IntPtLon areaSQMI LandSQMI TotPop rename=(puma22=puma TotPop=TotPop20) where=(sumlev='795')) ; by state puma; stab = "&ustab"; if first.state then do; length _divreg $2; _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 inacs and indhc) then do; putlog 'WARNING: Not on all datasets: ' state= puma= in1= inacs= indhc=; if in1; end; retain appsurl 'https://mcdc.missouri.edu/applications/applinks/links.php?g=79500US2901600'; substr(appsurl, 68, 2) = "&state"; substr(appsurl, 70, 5) = puma; * putlog 'NOTE: ' appsurl= ; * format placename $place. cbsaname $cbsa. csaname $csa. ; * Create the final value of PumaName by chopping off redundant ending such as PUMA: Alabama ; _ix = index(pumaname, 'PUMA'); if _ix then pumaname = substr(pumaname, 1, _ix-1); /* if place ne '99999' then do; length _pname $80 ; _pname = put(placename, $place.); %chopwrd(_pname); if not (zctaname =: _pname) then zctaname = trim(_pname)|| ", &ustab"; end; */ format AreaSQMI LandSQMI 9.2 ; format pct: 5.1; drop _: ; run; %mend doit; /* =========================Comment out===================================== %dostates(09, names=1); %dostates(10, names=1); %*genattr(setin=pumamstr.ctpumas); %* (optional) generate original template then edit later and include in convert step--; %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); pumamstr.&stab.pumas %mend setref; data georef.puma_master_2020(label="&year vintage PUMA master for U.S."); set %dostates(n=52,mac=setref) open=defer; run;