x cd /pub/data/acs2007/Tools; %let pgm=cnvt_geo_files; filename pgm "&pgm..sas"; *---Read data from the geo-header Summary files ascii files downloaded from ftp2.census.gov/acs2006/summaryfiles {OR SIMILAR} to create sas datasets. jgb, 9-08 12-08-08: Added code to do keyed lookup on georef.cbsacos to get cbsa, cbsatype and metrodiv assigned to 050 levels. ---*; %let period=3yr; %let subdir=%str(3yr/); %let period=%str(); %let subdir=%str(1yr/); %let year=2007; %let yr=%substr(&year,3,2); title "&pgm.: Convert &year &period Geographic headers Data"; libname acs2007 '/pub/data/acs2007'; *<====; libname georef '/pub/data/georef' access=readonly; *---Read and store the state geographic identifiers file---; data allgeos. infile "/pub/data/acs2007/geos/&subdir.*.txt" truncover lrecl=415; length SumLev $3 geoid $20 Name $120 AreaName $100 Geocomp_Name $64 State Stab $2 SumLev $3 Geocomp $2 LogRecno 8 County $5 CBSA $5 cbsaType $5 UA $5 PlaceFP $5 PUMA5 $5 sdelm sdsec sduni $5 Region Division $1 CongDist $2 MetroDiv $5 CSA $3 NECTA $5. ; *----We found a sas program to read these files on the Bureaus summary directory on the ftp site and used that to inform the columns from which the geocodes are read here. ---; cbsaType=' '; CBSAYr=' '; *<--being retained because we did a keyed read below--; input @7 Stab $2. SumLev $3. Geocomp $2. LogRecNo 7. +1 Region $1. Division $1. @26 state $2. _cnty $3. cousubfp $31-35 placefp $36-40 cbsa $76-80 metrodiv $84-88 csa $81-83 necta $91-95 ua $104-108 CongDist $114-115 puma5 $166-170 @138 (sdelm sdsec sduni)($5.) @176 geoid $20. @216 Name $120.; ***if state=' ' then state=_state2; if state='00' then state=' '; if stab=' ' and state=' ' then delete; length Geocode $12; geocode=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=' '; if geocomp ne '00' then do; Areaname=scan(name,1,';'); Geocomp_Name=scan(Name,2,';'); 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; set georef.cbsacos(keep=county cbsa cbsatype MetroDiv Year rename=(year=CBSAyr)) key=county; if _iorc_ then _error_=0; else _cbsayr=CBSAyr; retain _cbsayr; end; else if cbsa ne ' ' then do; if index(areaname,'Micropolitan') then cbsatype='micro'; else cbsatype='metro'; cbsayr=_cbsayr; end; if stab='PR' and state=' ' then state='72'; *<---this little glitch caused grief so we fix it here---; label CongDist='110th (2008) Congressional District'; drop _: ; run; proc sort out=acs2007.allgeos&period(index=(state) label="Geograpgy for ACS &period Data &year"); by State Logrecno; run; proc freq data=acs2007.allgeos. table state sumlev; format state $state. sumlev $sumlev.; table state*stab/list missing; run; options ls=160; proc print data=acs2007.allgeos&period (where= (state in('10','29')) drop=name geocomp_name); by state; id logrecno geoid; run; /* =======================Begin comment================ *----Run this check step to see what geographies may be missing or surprising------; data acs2007.geo_anomalies; merge acs2007.allgeos(in=in1) acs2007.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=acs2007.geo_anomalies; by anomaly state; title2 'Anomalies in the Two allgeos Data Sets'; run; ======================End comment================== */