x cd /pub/data/acs2014/Tools; %let pgm=cnvt_geo_files; filename pgm "&pgm..sas"; *---Read data from the geo-header Summary files ascii files (as downloaded and processed by Glenn Rice and sent to me as an e-mail attachment.) Will eventually creates the allgeos1yr , allgeos3yr and allgeos5yr data sets in acs2014 data directory. jgb, strting 9-12-15 Modeled after comparable job in 2012 Tools. ----The following was true at the time, but see below. Running with 1-year file 9-22-14. ---*; %let year=2014; %let period=1; *--can be 1, 3 or 5---; %*let period=3; *--can be 1, 3 or 5---; %let yearm4=%eval(&year-4); %let yearm2=%eval(&year-2); %let yr=%substr(&year,3,2); %***let cbsayr=13; %let cbsayr=13; title "&pgm.: Convert &year &period Geographic headers Data"; options compress=yes; libname acs&year "/pub/data/acs&year"; *<====; %let geosetname=allgeos&period.yr; libname georef '/pub/data/georef' access=readonly; *---Read and store the geographic identifiers CSV file---; filename geos "/pub/data/acs&year./geocodes&period.yr.csv"; *--Using attached file from Glenn, uploaded from UltraEdit--*; %macro lzeros(var,len); if &var ne " " and length(&var)<&len then do; &var=right(&var); &var=translate(&var,'0',' '); end; %mend lzeros; data allgeos. infile geos lrecl=500 dsd delimiter="," truncover firstobs=2; *<--we edited in a custom 1st line (from 2013) which we now skip--; length SumLev $3 geoid $40 AreaName $100 Geocomp_Name $2 esriid $24 State Stab $2 Geocomp $2 LogRecno 8 FipCo County $5 CousubFP PlaceFP $5 CBSA $5 cbsaType $5 metdiv $5 CSA $3 NECTA $5 CNECTA $3 NECTADiv $5 UA $5 uacp $5 PUMA5 PUMA1 $5 sdelm sdsec sduni $5 UR Region Division $1 CongDist $2 sldu sldl $3 ZCTA5 $5 Submcd $5; 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--; length _us $1 _stateCE $2 _cnty $3; input _acssf $ Stab SumLev Geocomp LogRecNo _us Region Division _stateCE State _cnty cousubfp placefp _tractin $ bg $ concit $ aianhh $ aianhhfp $ aihhtli $ aitsce $ aits $ anrc $ cbsa csa metdiv macc $ memi $ necta cnecta nectadiv ua uacp congdist sldu sldl _vtd $ _zcta3 $ zcta5 submcd sdelm sdsec sduni ur _pci $ _Taz $ _uga $ puma5 puma1 geoid AreaName ; *** 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_=1 then list; *--make sure we are getting that first record for Alaska no geocomp---; *if _N_ le 500 then do; *<========ONLY while testing================; * file "/pub/data/acs/sample_geos" lrecl=1000; * put _infile_; *file log; * end; *--------Prior to the 2014 files these geocodes appeared as character string with leading zeros. But not this time!--; %lzeros(Geocomp,2); if _n_=1 then if geocomp ne '00' then do; put _all_; stop; end; *<====================================; %lzeros(Sumlev,3) %lzeros(_stateCE,2) %lzeros(State,2) %lzeros(_cnty,3) %lzeros(cousubfp,5) %lzeros(placefp,5) %lzeros(tractin,6) %lzeros(cbsa,5) %lzeros(csa,3) %lzeros(necta,5) %lzeros(ua,5) %lzeros(uacp,5) %lzeros(puma5,5) %lzeros(puma1,5) %lzeros(sdelm,5) %lzeros(sdsec,5) %lzeros(sduni,5) %lzeros(congdist,2) %lzeros(sldu,3) %lzeros(sldl,3) %lzeros(zcta5,5) %lzeros(summcd,5) _ix=index(areaname,'0D'x); *---these characters somehow were appended to the areanames---; if _ix then substr(areaname,_ix)=' '; 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 gt '00' then do; _idashdash=index(Areaname,'--'); Areaname=substr(Areaname,1,_idashdash-1); Geocomp_Name=geocomp; format geocomp_name $geocomp.; *<---so the code displays as the geocomp title---; end; ***if sumlev='050' then do; if county ne ' ' then do; *--get the metro codes attached to any level with county specified.--; if county ne lag(county) then do; set georef.cbsacos&cbsayr (keep=county cbsa cbsatype metrodiv Year rename=(year=CBSAyr metrodiv=metdiv)) key=county; if _iorc_ =0 then _cbsayr=CBSAyr; retain _cbsayr; _savecbsa=cbsa; _savemetdiv=metdiv; _savecbsatype=cbsatype; retain _save: ; end; else do; cbsa=_savecbsa; metdiv=_savemetdiv; cbsatype=_savecbsatype; cbsayr=_cbsayr; end; end; else if cbsa ne ' ' then do; if index(areaname,'Micro') > 1 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---; *---this still caused problems when we tried to merge with the base tables where state is blank for these sumlevs. So now we try a different approach---; if stab='PR' and sumlev in ('310','330','400') then do; state=' '; stab=' '; end; drop _: ; 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; _nput+1; if _nput=1 then put '*****Putting all variables when detecting change in Sumlev - up to 25 cases*****' ; if _nput le 25 then put / _all_; end; output; *--so we can reset the variables that may have been read with a keyed read to get cbsa codes--; cbsa=' '; metdiv=' '; cbsatype=' '; *if _n_ gt 500 then stop; *<=====; label CongDist='114th (2014) Congressional District'; *<================; 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' uacp='UA central place' PUMA5='2010 PUMA' sduni='Unified Schl Dist' sldu='State Leg Dist - Upper Chamber' sldl='State Leg Dist - Lower Chamber' ZCTA5='5-digit ZIP/ZCTA' ; *** Uncomment for 5yr run: label bttr='Tribal Tract' BTBG='Tribal BG'; run; proc sort out=acs&year..&geosetname (index=(state) label="Geography for ACS &period,yr Data Vintage &year"); by State geoid; run; proc datasets library=acs&year; modify &geosetname; index create geoid; quit; options ls=160; proc freq data=acs&year..&geosetname ; table sumlev*set/nopercent nocum; format sumlev $sumlevwc.; table state*stab/list missing ; run; /*<=========================Comment out===================================== *----Run this check step to see what geographies may be missing or surprising------; data acs&year..geo_anomalies; merge acs&year..allgeos1yr(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 commented out================================ */