x cd /pub/data/georef/Tools; %let pgm=puma_master12; filename pgm "&pgm..sas"; *---We are creating this setup using the zcta_master12 setup as our template. We want to do for PUMAs what we did for ZCTAs-; *---This setup creates the georef.puma_master12 dataset based on geographic reference data from the mable14 database, as revised summer, 2012. It also includes data from the most recently available ACS data (2013 1-year). The rows/observations in these datasets correspond to the latest PUMA codes (officially called 2010 but we prefer 2012 because that was the year when they began being used. Before then the Bureau was publishing vintage 2011 ACS data using the old 2000 PUMAs. We are not keeping any MOE (margin of error) estimates for the ACS data on these datasets. jgb, December, 2014. ---*; libname georef '/pub/data/georef'; libname pumamstr '/pub/data/georef/pumamstr'; %libname (mable14); %libname (sf12010x); %let acsvintage=2013; %let acsyears=&acsvintage; %libname(acs&acsvintage,opts=); libname acs (acs&acsvintage); libname corrlst '/pub/data/corrlst' access=readonly; options fmtsearch=(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 added 8-15-13----; %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=puma12 ZCTA5 County CouSubFP PlaceFP pop10 intptLat intptLon LandSQMI ur ua cd113 puma2k cnty2k state &nectavars CBSA Metdiv cbsatype csa PopGrowthFactor) out=sortedcodes(compress=NO); by puma12 county; run; data geocodes(compress=NO); set sortedcodes; length gtype $6 geocode $5; array geocodes(*) county Cousubfp placefp ur ua cd113 puma2k zcta5 cnty2k &nectavars cbsa metdiv csa cbsatype; retain _gtypes "cou mcd pla ur ua cd puma2k zcta co2 &nectatyps cbsa metdiv csa cbsat "; pop12=pop10*PopGrowthFactor; *---This was the county pop estimate in 2012 over the 2010 census pop for county.---; do _i=1 to dim(geocodes); geocode=geocodes{_i}; gtype=scan(_gtypes,_i); output; end; keep state puma12 gtype geocode pop10 pop12; run; proc sort; by puma12 gtype geocode; run; %corrwt(setin=geocodes,setout=&stab.corrwt,g1=state puma12 gtype,g2=geocode,wtvar=pop12,keepwt=0); proc sort; by state puma12 gtype descending afact; proc print data=&stab.corrwt (obs=100); title2 "&stab.corrwt"; run cancel; data &stab.data; set &stab.corrwt; by state puma12 gtype ; ***where puma12 ne '99999'; length pumaName $80; if first.puma12 then do; length _arg $7; _arg=state||puma12; PumaName=put(_arg,$puma.); end; retain; length County County2 PlaceFP PlaceFP2 $5 CouSubFP CouSubFP2 $5 cd113 cd113_2 $2 puma2k zcta5 $5 necta nectaDiv $5 Cnecta $3 cbsa $5 MetDiv $5 csa $3 CBSAType $5 ; if first.puma12 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('co2') do; if _ng=1 then do; cnty2k=geocode; pctcnty2k=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; cousubfp=geocode; pctcousub=100*afact; 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; end; else do; cd113_2=geocode; end; end; *when('msa') do; * if _ng=1 then do; * msacmsa=geocode; * pctmsacmsa=100*afact; * end; * else if msacmsa='9999' then do; * msacmsa=geocode; * pctmsacmsa=100*afact; * end; * end; when('puma2k') do; if _ng=1 then do; puma2k=geocode; pctpuma2k=100*afact; end; if _ng=2 then do; puma2k2=geocode; pctpuma2k2=100*afact; 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; zcta5=geocode; pctzcta5=100*afact; end; else if _ng=2 then do; zcta52=geocode; pctzcta52=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.puma12 then do; Fipco=county; FipCo2=County2; 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 format codes with storing actual names--; ***UAName=ua; ***length Puma12Name $7; ***puma12Name=state||puma12; length UAName $96 PumaName $80; UAName=put(ua,$uauc.); length ZCTA5Name $80; ZCTA5Name=put(zcta5,$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 County2 $county. PlaceName $fplace. CBSAName $cbsa. nectaname $necta. MetDivname $metrodiv. csaname $csa.; format Pct: 5.1; output; RENAME puma12 = PUMA; ****************************NOTE******************************************; end; drop gtype geocode afact i _: ; run; proc print data=&syslast; title2 "&syslast"; by state; id zcta5; run cancel; 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--; *--Note that these are single-year data, NOT the 5yr period estimates we used on the zcta_master----*; set acs&acsvintage..usmcdcprofiles_&acsvintage(keep=geoid state SumLev &geovars 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,10,5); drop geoid; *** Rename=(TotPopSF1=TotPop10) ***; **we also omitted totpopsf1 from the keep= list, just above--; ACSYears="&acsyears"; Period="1"; rename TotPop=TotPopACS; label TotPop="Total Pop ACS &acsyears Single-Year Est"; run; data pumamstr.&stab.pumas(label="&statenm PUMA Master Reference" sortedby=state puma compress=no ); %include attrib/NOsource2; ***length State Stab $2 PUMA $5; merge &stab.data (in=in1) &stab.acsdata(in=inacs) sf12010x.&stab.cdsldspumas2012(in=insf1 keep=sumlev state puma12 IntPtLat IntPtLon areaSQMI LandSQMI TotPop rename=(puma12=puma TotPop=TotPop10) where=(sumlev='795')) ; by state puma; 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 inacs and insf1) then do; put '**Not on all datasets: ' state= puma= in1= inacs= insf1=; if in1; end; retain appsurl 'https://mcdc.missouri.edu/applications/applinks/links.php?g=79500US2901600'; *--worked 12/14 at least--; substr(appsurl,56,2)="&state"; substr(appsurl,58,5)=puma; 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 placefp ne '99999' then do; length _pname $80 ; _pname=put(placename,$place.); %chopwrd(_pname); if not (zcta5name=:_pname) then zcta5name=trim(_pname)|| ", &ustab"; end; format AreaSQMI LandSQMI 9.2 ; format pct: 5.1; *rename zcta5=ZCTA zcta52=ZCTA2 pctzcta5=PctZCTA pctzcta52=PctZCTA2 ZCTA5Name=ZCTAName; ZCTA=zcta5; ZCTA2=zcta52; PctZCTA=pctzcta5; pctzcta2=pctzcta52; zctaname=zcta5name; drop zcta5 zcta52 pctzcta5 pctzcta52 zcta5name; drop _: ; run; %mend doit; options NOmprint; *<====; /*<=========================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=51,msgs=1,names=1) ; %macro setref(state,stab); pumamstr.&stab.pumas %mend setref; data georef.puma_master(label="&year vintage PUMA Master for U.S." compress=yes); set %dostates(n=51,mac=setref) open=defer; run; %*metahtml(filetype=georef,setin=puma,specific=1, keywords=puma 2010 master geographic characteristics urban rural metro city county demographics acs data, replace=0) ; run; options nofmterr; data two; set pumamstr.capumas (obs=2); run; proc printto print='../puma_master.sample2pumas.txt' new; run; proc fsbrowse data=two printall; run;