x cd /pub/data/georef/Tools; %let pgm=pumas_counties_places; filename pgm "&pgm..sas"; *---create datasets and a report for all US states that shows the relationship between PUMAs and counties and places. It basically has 1 obs per 5% PUMA showing the Super PUMA (sorted by Super Puma and then 5% PUMA), and then a list of counties and places. The 2 datasets are georef.puma_county and georef.puma_place and the report is in webrepts/geography/&pgm..pdf . Source is the mable2k database and a small super-puma to puma txt file we found in the corrlst directory. JGB, OSEDA, 9/2006. ---; libname georef '/pub/data/georef'; libname corrlst '/pub/data/corrlst'; %libname(mable2k); libname user '/SAS_temp/userb'; %let state=10; %let stab=de; %**let stname=Delaware; %let state=29; %let stab=mo; %**let stname=Delaware; %macro doit(state,stab); %local ustab; %let ustab=%upcase(&stab); data codes&state.v/view=codes&state.v; set mable2k.&stab.v2(keep=puma5 county02 placesc placefp state pop2k); if upcase(placesc) le 'D' then placefp='99999'; *--we only keep detail for places of 2500+ --; rename county02=county; run; proc sort data=codes&state.v out=codes&state; by puma5 county placefp; run; data codes&state.c; set codes&state; by puma5 county placefp; if first.placefp then pop2ks=0; pop2ks + pop2k ; if last.placefp then output; *--one obs per combination of puma5, county and edited placefp--; keep state puma5 county placefp pop2ks; run; proc sort data=codes&state.c; by placefp puma5; run; %corrwt(setin=codes&state.c,setout=pl2puma&state, g1=state placefp,g2=puma5,wtvar=pop2ks,keepwt=1); proc sort data=codes&state.c; by county puma5; run; %corrwt(setin=codes&state.c,setout=co2puma&state, g1=state county,g2=puma5,wtvar=pop2ks,keepwt=1); proc sort data=pl2puma&state; by puma5 placefp; run; proc sort data=co2puma&state; by puma5 county; run; *---create the dataset with the Counties string that has names and portions of counties intersecting each puma---; data puma_county_&stab; set co2puma&state; by puma5; length Counties $640; retain counties; if first.puma5 then do; counties=' '; pumapop2k=0; end; length cntyname $40; cntyname=put(county,$county.); _ix=index(cntyname,"&ustab. "); *---remove the state abbreviation at end of name, if present--; if _ix then cntyname=substr(cntyname,1,_ix-1); counties=trim(counties)||' / '||cntyname; ** if _n_ le 10 then put / _all_; if afact lt .99 then do; length _afact $3; _afact=put(round(afact*100),2.); counties=trim(counties)||'('||trim(left(_afact))||'%)'; end; pumapop2k+pop2ks; if last.puma5 then do; counties=substr(counties,4); output; end; keep State puma5 Counties pumapop2k; format pumapop2k comma9.; run; *---create the dataset with the Places string that has names and portions of places (2500+) intersecting each puma---; data puma_PLACE_&stab; set pl2puma&state; by puma5; length Places $800; retain places; if first.puma5 then do; places=' '; pumapop2k=0; end; length plcname $40; length _arg $7; if placefp ne '99999' then do; _arg=state||placefp; plcname=put(_arg,$fplace.); %chopwrd(plcname,unless=CDP) *--remove last work in name such as "city", "town", "village", etc.--; if _n_ le 10 then put / _all_; end; else plcname='Other'; places=trim(places)||' / '||plcname; if afact lt .99 then do; length _afact $3; _afact=put(round(afact*100),2.); places=trim(places)||'('||trim(left(_afact))||'%)'; end; pumapop2k+pop2ks; if last.puma5 then do; places=substr(places,4); output; end; keep State puma5 Places pumapop2k; format pumapop2k comma9.; run; %mend doit; /* =======================Begin comment================ options NOmprint; %dostates(n=51,names=1,msgs=1); *------We have at this point successfully created 2 x 51 datasets for the states and one national puma1-puma5 dataset. we now want to merge all of these together, by state and puma5, to create the final keeper dataset, georef.pumas_counties_places . And then we'll generate a pdf report of this dataset in webrepts/geography. -----; *--concatenate the 51 counties datasets--; %macro doit( state,stab); puma_county_&stab %mend doit; data puma_county_us; set %dostates(n=51,names=1,msgs=1) open=defer; run; *--concatenate the 51 places datasets--; %macro doit( state,stab); puma_place_&stab %mend doit; data puma_place_us; set %dostates(n=51) open=defer; run; proc sort data=corrlst.uspumas2k out=puma2superpuma; by state puma5; run; *---And, finally, merge the 3 sets together to create the final georef dataset----------------*; data &pgm; merge puma2superpuma(in=insuper) puma_county_us(in=inc) puma_place_us(in=inp); by state puma5; if not insuper and inc and inp then do; _nbad+1; if _nbad le 10 then put / _all_; else abort abend; end; drop _:; label puma1='Super PUMA' puma5='5% PUMA' Counties='Counties Comprising the PUMA' Places='Places (Cities, towns, etc.) Comprising the PUMA' pumapop2k='Total Pop of 5% PUMA, 2000 Census'; run; proc sort data=&pgm out=georef.&pgm (label='Relates all US 5 Pct PUMAs to Super PUMAs and Counties and Places (names lists)' index=(state)); by State puma1 puma5; run; ======================End comment================== */ ods listing close; options ls=175 orientation=landscape nodate; ods pdf file="/pub/reports/geography/&pgm..pdf" ; title '2000 PUMA Codes Showing What Counties and Cities Comprise Them'; title2 'U.S. by State'; proc print data=georef.&pgm label; *=========================testing only!!!=========; ***where state le '04'; by state; *pageby state; id puma1 puma5; format state $state. pumapop2k comma9.; var pumapop2k counties places; label pumapop2k='PUMA Pop 2K Census'; footnote 'Source: MABLE2k - Master Area Block Level Equivalency File'; footnote2 'Pcts Shown are Portions of the County/Place Within the 5% PUMA Based on 2000 Population'; footnote3 'Places under 2500 and not-in-place areas are collapsed into "Other" Category'; run; ods pdf close;