x cd /pub/data/acs/Tools; %let pgm=gen_tbsa_codingfile; filename pgm "&pgm..sas"; *---generate a coding file (csv to become xls) that can be used to define tract-based statistical areas (TBSAs). This involves getting the correspondences of PUMA-county-census tract (the old 2000 geographies for now) and corresponding 2k pop counts and latest 5-yr period estimated pops. jgb, 12/2010 . ---*; filename geocrin '/pub/data/acs/tbsacoding/mopumatract2k.csv'; *<--Geocorr equivalency: puma to census tract with 2k pops--; libname acs2009 '/pub/data/acs2009'; *---where latest 5yr period estimates for tracts are stored--; libname corrlst '/pub/data/corrlst' access=readonly; libname user '/SAS_temp/user'; title "&pgm.: Generate Coding File for Capturing TBSA Definitions"; /* ========================begin comment==================================== *--read the geocorr file to get tracts that go with pumas and their 2k pops--; data pumatract2k; infile geocrin dsd firstobs=3; length PUMA $5 State $2 placefp $5 county $5 tract $7 pop2k 5 ; input PUMA--pop2k; puma=translate(right(puma),'0',' '); if length(placefp) < 5 then placefp=translate(right(placefp),'0',' '); if index(tract,'.')=0 then tract=trim(tract)||'.00'; tract=translate(right(tract),'0',' '); if substr(tract,6,1)='.' then tract=substr(tract,2,4)||'.'||substr(tract,7,1)||'0'; *-e.g. 700110 became 07001.1 yuk--; if placefp='99999' then inplace=0; else inplace=1; ***if _n_ le 25 then put _all_; run; proc sort; by puma county tract inplace pop2k ; run; data pumatract2kedited; set; by puma county tract inplace; if first.county then _CountyPop=pop2k; else _CountyPop+pop2k; if first.tract then Location=' '; retain Location; if first.tract then _TractPop=pop2k; else _TractPop+pop2k; if inplace and last.inplace then Location=state||placefp; *--this is the place most associated with tract--; if last.tract then do; if _tractPop ne 0 then PctinLoc=100*pop2k/_tractPop; format PctinLoc 5.1; pop2k=_TractPop; output; end; if last.county then do; tract='**All**'; pop2k=_countypop; placefp=' '; location=' '; PctInloc=.; output; end; drop _: inplace; format location $fplace.; run; proc print data=pumatract2kedited (obs=1000); title2 "first 100 Obs on pumatract2kedited"; by state puma ; id county tract; format county $county.; run; proc sort; by county tract; *--prep for merge with ACS data---; *---read the latest acs 5-year data at tract level to get an estimate of current tract pop (FWIW)---; data tractpopsacs; set acs2009.usmcdcprofiles5yr(keep=sumlev state totpop geoid); where state='29' and sumlev in ('050','140'); length county $5 tract $7; county=substr(geoid,8,5); if sumlev='140' then tract=substr(geoid,13,4)||'.'||substr(geoid,17,2); else tract='**All**'; keep county tract totpop; rename totpop=PopEst0509; run; proc sort; by county tract; run; data almost_final; retain State PUMA County Tract; merge pumatract2kedited(in=in2k) tractpopsacs(in=inacs); by county tract; if not (in2k and inacs) then do; put "***missing data*** " county= tract= in2k= inacs= ; _nbad+1; if _nbad ge 50 then abort abend; drop _nbad; end; run; proc sort out=acs2009.tbsa_codingfiledata(label="See setup in acs/Tools/&pgm..sas"); by puma county tract; run; proc print data=acs2009.tbsa_codingfiledata(obs=200); title2 "Final data set: acs2009.codingfiledata"; by state puma; id county; format county $county.; run; ==========================end comment====================================== */ *----and now generate the output csv/coding file------------------*; *---just do a boone county subset for now---; filename csvout '/pub/data/acs/tbsacoding/codingform.csv' lrecl=512; *--the output file / coding form --; proc sort data=acs2009.tbsa_codingfiledata(where=( substr(puma,1,3) in ('015','016','017','018','019') and tract ne '**All**')) out=stltracts; by county tract; run; data toxtract; *set acs2009.tbsa_codingfiledata; merge stltracts (in=keeper) corrlst.tr2k2stltra(drop=grctractid in=inclist); by county tract; if keeper; if not inclist then put _all_; format county $5.; run; proc sort; by puma county tract; run; proc export data=toxtract dbms=csv outfile=csvout replace; run;