x cd /pub/data/acs2011/Tools; %let pgm=cnvt_geo_files; filename pgm "&pgm..sas"; *---The rerun in April did not work becuase the input file was missing--------------------; *---Read data from the geo-header Summary files ascii files (as downloaded and processed by Billy Earney) to create sas datasets. jgb, 11-12. Ran 1-3-13 and again 4-10-13. This time to get cbsa related codes whenever we know the county. We changed the cbsa lookup data set to georef.cbsacos09 . Do NOT do that next year! Modeled after acs2007 setup of the same name. ---*; %let year=2011; %let yearm4=%eval(&year-4); %let period=&yearm4._&year; %let yr=%substr(&year,3,2); title "&pgm.: Convert &year &period Geographic headers Data"; options compress=yes; libname acs&year "/pub/data/acs&year"; *<====; libname user '/SAS_temp/userb'; libname georef '/pub/data/georef' access=readonly; *---Read and store the state geographic identifiers file---; *filename geos "/web/mcdc/scripts2/acs/&period./geocodes/geocodes.txt"; filename geos "/web/mcdc/scripts2/geocodes_2007_2011.txt"; *--Glenn put this file here 12-27-12--; data allgeos. infile geos lrecl=2100 truncover; length SumLev $3 geoid $40 AreaName $100 Geocomp_Name $2 esriid $16 State Stab $2 Geocomp $2 LogRecno 8 FipCo County $5 CousubFP PlaceFP $5 CBSA $5 cbsaType $5 metdiv $5 CSA $3 NECTA $5 UA $5 PUMA5 $5 sdelm sdsec sduni $5 Region Division $1 CongDist $2 ; length set $3; *<---This variable is our (MCDC) invention. Values are bgs, trs, and all. How we plan to split our datasets, with block group and tract levels in separate sets.------------; cbsa=' '; cbsaType=' '; CBSAYr=' '; metdiv=' '; *<--being retained because we did a keyed read below--; input _acssf $5. +1 Stab $2. SumLev $3. Geocomp $2. LogRecNo 7. +1 Region $1. Division $1. +2 state $2. _cnty $3. cousubfp $char5. placefp $char5. _tractin $char6. bg $1. concit $char5. +4 aianhhfp $char5. aihhtli $1. +3 aits $char5. anrc $char5. @71 cbsa $char5. csa $char3. metdiv $char5. (macc memi) ($1.) necta $char5. cnecta $char3. nectadiv $char5. ua $char5. +5 congdist $2. (sldl sldu)($char3.) +9 zcta5 $char5. @136 submcd $char5. (sdelm sdsec sduni)($5.) ur $1. pci $1. +11 puma5 $char5. +5 _geoid $40. _Name $1000. bttr $char6. BTBG $char1. ; if _acssf ne 'ACSSF' then do; file log; put "Input data line does not contain correct filetype in cols 1-5 (ACSSF expected)"; list; abort abend; end; *if _N_ le 500 then do; *<========ONLY while testing================; * file "/pub/data/acs/sample_geos" lrecl=1000; * put _infile_; *file log; * end; ***if state=' ' then state=_state2; if state='00' then state=' '; if stab=' ' and state=' ' then delete; geoid=_geoid; esriid=substr(geoid,8); *---the codes identifying the area without SumLev and Geocomp and "US" from geoid-; if _cnty ne ' ' then County=State||_cnty; else County=' '; Fipco=county; format fipco $5. county $county.; if geocomp ne '00' then do; _idashdash=index(_name,'--'); Areaname=substr(_name,1,_idashdash-1); Geocomp_Name=geocomp; format geocomp_name $geocomp.; *<---so the code displays as the geocomp title---; end; else Areaname=_name; if state='29' and sumlev='795' then Areaname=puma5||' '||put(puma5,$mopuma.); *<---substitute names for the MO pumas---; ***if sumlev='050' then do; if county ne ' ' then do; *--rerunning 4-10-13 to get the metro codes attached to any level with county specified.--; set georef.cbsacos09(keep=county cbsa cbsatype metrodiv Year rename=(year=CBSAyr metrodiv=metdiv)) key=county; *---------------XX---------: note that we use previous version to get the old 2009 vintage cbsa defns. We have the new 2013 data in cbsacos but we will start using those next year in the vintage 2012 cycle-----; if _iorc_ then _error_=0; else _cbsayr=CBSAyr; retain _cbsayr; end; else if cbsa ne ' ' then do; *--Presumably cbsa or partial cbsa summaries---; if index(areaname,'Micropolitan') then cbsatype='micro'; else cbsatype='metro'; cbsayr=_cbsayr; end; *--This is a problem caused by the data for PR coming in with the 310 levels (etc) having PR as the stab. These should have been with the us summaries (stab='US'). But if we change PR to US then we have a problem because logrecno will not be sequential within the US group. Kind of a mess.--; if stab='PR' and state=' ' then state='72'; *<---this little glitch caused grief so we fix it here---; label CongDist='112th (2010) Congressional District'; *<================; drop _: ; drop uacp uag; *--what are/were they? Always appear to be blank so why keep. --; if sumlev ne lag(sumlev) then do; if sumlev='150' then set='bgs'; else if sumlev in ('080','140') then set='trs'; else set='all'; retain set; file log; *list; put _all_; end; *if _n_ gt 500 then stop; *<=====; label geoid='Geographic ID (Census)' SumLev='Geog Summary Lvl' Geocomp='Geog Component' PlaceFP='Place (city) Code' CousubFP='County Subdiv (Town) code' metdiv='Metro Division of MSA' CSA='Consolidated Stat Area' NECTA='New England City/Town Area' UA='Urban Area/Cluster' PUMA5='2000 PUMA (5%)' sduni='Unified Schl Dist' sldu='State Leg Dist - Upper Chamber' sldl='State Leg Dist - Lower Chamber' bttr='Tribal Tract' BTBG='Tribal BG'; label ZCTA5='5-digit ZIP/ZCTA' ; ***drop zcta5; *<========================Does not appear until the 2011 cycle=========================; run; proc sort out=acs&year..allgeos&period(index=(state) label="Geography for ACS &period Data &year"); by State geoid; run; options ls=160; proc freq data=acs&year..allgeos. table sumlev*set/nopercent nocum; format sumlev $sumlevwc.; table state*stab/list missing ; run; /* =======================Begin comment================ *---NOT running this cycle because we do not have allgeos and allgeos3yr datasets (yet)----; proc print data=acs&year..allgeos&period (where= (state in('10','29')) drop=name geocomp_name); by state; id logrecno geoid; run; *----Run this check step to see what geographies may be missing or surprising------; data acs&year..geo_anomalies; merge acs&year..allgeos(in=in1) acs&year..allgeos3yr(in=in3); by geoid; length default=3; if in1 and not in3 then Anomaly='In 1-Year but not in 3-yr'; if sumlev='795' and not in1 then Anomaly='PUMA not in 1-Yr'; if anomaly ne ' '; In1Yr=in1; In3Yr=in3; run; proc sort; by anomaly state; run; proc print data=acs&year..geo_anomalies; by anomaly state; title2 'Anomalies in the Two allgeos Data Sets'; run; ======================End comment================== */