x cd /home/riceg/ZCTAs; %let pgm=zcta_master17; filename pgm "&pgm..sas"; *---This setup creates the georef.zcta_master12 dataset based on geographic reference data from the mable14 database, as revised summer, 2012. It also includes data from the ZCTA to state correlation list and from the most recently available ACS data (5-year estimate so that all ZCTAs have data). The rows/observations in these datasets correspond to 5-digit ZIP Census Tract Area ("ZCTA") codes within state, as used for ************ 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; else do; cousubfp2=geocode; 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; end; when('puma12') do; if _ng=1 then do; puma12=geocode; pctpuma12=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.zcta5 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 Puma12Name $80; UAName=put(ua,$uauc.); length _arg $7; _arg=state||puma12; Puma12Name=put(_arg,$puma.); %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; *--replacing old code with new here, 8-13. Old code commented out.------*; **_uaname=put(ua,$uauc2k.); **if scan(_uaname,-1,' ')='(UA)' then uatype='UA'; ** else uatype='UC'; *--urban cluster or urbanized area?--; _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 PUMA12Name $puma. UAName $uauc.; format Pct: 5.1; output; end; drop gtype geocode afact i _: ; run; proc print data=&syslast; title2 "&syslast"; by state; id zcta5; run cancel; *-----The ACS ZCTA data is for COMPLETE ZCTAs (NOT within state!). The State variable that we added is just the "primary" state. Which is not so good for us because we would prefer to build a data set that is state/zcta based. But... ----*; data &stab.acsdata; set acs.uszctas5yr(keep=esriid state zcta5 stab PctState SumLev IntPtLat Intptlon Landsqmi AreaSQMI TotPopSF1 TotPop MedianAge pctUnder18 pctOver65 pctwhite1 pctblack1 pctasian1 pctHispanicPop TotHHs MedianHHInc FamHHs MedianFamInc PovUniverse PctPoor pctGrpQuarters pctBachelorsormore pctInCollege pctForeignBorn TotHUs OccHUs pctRenterOcc MedianHValue MedianGrossRent Rename=(TotPopSF1=TotPop10) Where=(state="&state" and zcta5 ne '99999' and TotPop) ); if zcta5 ne ' '; ACSYears="&acsyears"; ** drop Years; *<=================Variable Years not on ACS set this cycle-; format AreaSQMI LandSQMI 9.2 ; rename TotPop=TotPopACS; label TotPop="Total Pop ACS &acsyears Period Est"; run; proc sort data= corrlst.zip_2_zcta15(where=(stab="&ustab" and (zip ne zcta)) drop=ZIPType CityName ) out=altzips; by zcta; run; data altzips2; set altzips; by zcta; length AltZIPs $356 NaltZIPs 3; retain State "&state" AltZIPs; if first.zcta then do; AltZIPS=ZIP; Naltzips=1; end; else do; naltzips+1; AltZIPs=trim(altZIPS)||' '||zip; end; if last.zcta then output; keep state zcta naltzips altzips; rename zcta=zcta5; run; data zctamstr.&stab.zips(label="&statenm ZCTA Master Reference" compress=yes sortedby=state zcta5); %***include attrib/NOsource2; merge &stab.data (in=in1) corrlst.us_zip2010_state(in=inzpst keep=zcta5 state nparts primary Pop2010 ZipTotPop pctpop rename=(nparts=Nstates primary=psf pctpop=pctState Pop2010=Pop10ZCTAstate)) georef.zcta_splitstates(where=(state="&state") keep=state zcta5 state2 stab2 PctState PctState2 Pop10State2 in=insplit) altzips2(in=inaltzips) &stab.acsdata(in=inacs) ; *---Adding the splitstates set to merge for July 2014 run where we now have the secondary state data---; by state zcta5; 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; *if not (in1 or inacs) then delete; if not inacs then delete; *<====new criteria Aug. 2013===; label ZIPTotPop='ZCTA 2010 total across all states'; 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 inzpst) then do; put '**Not on all datasets: ' state= zcta5= in1= inacs= inzpst= inaltzips=; if in1; * if not in3 then pop2k=.; end; if not inaltzips then Naltzips=0; *** retain appsurl 'mcdc.missouri.edu/cgi-bin/applinks/applinks.py?geoid=86000USZZZZZ'; *substr(appsurl,48,2)="&stab"; ***substr(appsurl,62,5)=zcta5; format placename $place. cbsaname $cbsa. csaname $csa. ; *----Create the final value of ZIPName by using the name of the primary place, if applicable. We chop off the place type owrd ("city", "CDP", etc.) and replace it with ", &stab" ----; if placefp ne '99999' then do; length _pname $80 ; _pname=put(placename,$place.); %chopwrd(_pname); if not (zipname=:_pname) then zipname=trim(_pname)|| ", &ustab"; end; label Pop10ZCTAstate='2010 Pop in just the state portion of ZCTA'; drop _: ; run; %mend doit; options mprint; *<====; options compress=yes; %**dostates(38,names=1); %dostates(n=51,msgs=1,names=1) ; %*genattr(setin=zctamstr.dezips); %*---(optional) generate original template then edit later and include in convert step--; %macro setref(state,stab); zctamstr.&stab.zips %mend setref; data georef.zcta_master(label='2012 vintage ZCTA Master for U.S.' compress=yes); set %dostates(n=51,mac=setref) open=defer; run; %*metahtml(filetype=georef,setin=zcta_master,specific=1, keywords=zip zcta master geographic characteristics urban rural metro city county demographics, replace=0) ; run; options nofmterr; data two; set georef.zcta_master; where zcta5 in ('63105','97635'); *--Just pick two--; run; proc printto print='../zcta_master.sample2zips.txt' new; run; proc fsbrowse data=two printall; run;