x cd /pub/data/sf12000/Tools; %let pgm=cnvtsf1_xxgeos; filename pgm "&pgm..sas"; *---This program will read the sf1 (2000 Census) geographic headers files and create a series of geographic headers data sets. We read files for all 50 states + DC and we create sas data sets sf1.xxblks, for xx in {al, ak, ..., wy} as well as sf1.xxgeos collections (all geo. levels except blocks) and sf1.usgeos_places, usgeos_cousubs, usgeos_tracts, usgeos_zctas, .... which are SAS views based on concatenating and subsetting the xxgeos data sets. John Blodgett, OSEDA, U. of Missouri Under contract with the Missouri Census Data Center. Part of the joint project of the national State Data Center. Adapted from cnvtsf1.sas in this same Tools directory. See that module for extensive usage notes regarding using permanent sas format codes, etc. Oct, 2001. ---*; *-------Revision history: Begin coding, 10-16-01 --------*; libname user '/tmp/storage/john'; filename curpath '/pub/data/sf12000/xxgeos'; %let inpath=%str(/pub/data/sf12000/xxgeos); *<===path (directory) where the input xxgeo_uf1.zip files are stored---*; libname sasout "&inpath"; *<===========output sas data sets stored is same dir as input files======; x cd &inpath; *<---make it the current directory--; %let stab=de; %let state=de; *<----Delaware for testing---; %let maxobs=9999999; %macro concatd(g1,g2,g3,g4,g5,g6,g7,g8); %*--utility macro used to create geocode values-; %*--utility macro to return a SAS expression that will be the concatenation of specified char variables separated by dashes-; %local dash gc; %let dash=%str(||'-'||); %*--we build the value of local variable gc which is then "returned" as the result of invoking the macro-; %let gc=&g1; %if &g2= %then %goto rtrn; %let gc=&gc&dash&g2; %if &g3= %then %goto rtrn; %let gc=&gc&dash&g3; %if &g4= %then %goto rtrn; %let gc=&gc&dash&g4; %if &g5= %then %goto rtrn; %let gc=&gc&dash&g5; %if &g6= %then %goto rtrn; %let gc=&gc&dash&g6; %if &g7= %then %goto rtrn; %let gc=&gc&dash&g7; %if &g8= %then %goto rtrn; %let gc=&gc&dash&g8; %rtrn: &gc %mend concatd; %macro doit(state,stab); filename geos pipe "unzip -a -p &stab.geo_uf1"; data geos blks (drop=areaname); infile geos missover lrecl=1024 obs=&maxobs; retain _first 1; drop _first; length geo_id 5 GeoCode $44 SumLev $3 GeoComp $2 AreaName $90 ; *--establish variable order -- these go first--; retain State "&state" Stab "&stab"; length County $5 Tract $7 Block $4; *--and then these... -; if _first then do; input FileId $char6. stusab $2. @; retain FileId stusab; drop fileid stusab; if substr(FileId,2,3) ne 'SF1' then do; file log; put '******Problem with input geographic headers file. Did not find "SF1" in cols. 2-4 ' FileId= / '***Conversion will not run***'; list; stop; end; end; input @9 SumLev $3. geocomp $2. @19 LogRecNo 7. @26 Region $1. Division $1. StateCe $2. State $2. Cnty $3. CntySC $2. @37 CouSubFP $5. CouSubCC $2. CouSubSC $2. PlaceFP $5. PlaceCC $2. PlaceDC $1. PlaceSC $2. @56 TractIn $6. BG $1. Block $4. @69 ConCit $5. @78 aianhh $char4. aianhhfp $char5. aianhhcc $char2. aihhtli $1. aitsce $char3. aits $char5. aitscc $char2. anrc $char5. anrccc $char2. @107 MSACMSA $4. MASC $2. CMSA2 $2. MACCI $1. PMSA $4. NECMA $4. @136 UrbanRur $1. cd106 $2. +6 (sldu sldl)($char3.) vtd $char6. vtdi $1. @158 ZCTA3 $3. ZCTA5 $5. @173 (AreaLand AreaWatr)(14.) AreaName $90. FuncStat $1. gcuni $1. @293 Pop100 9. HU100 9. IntPtLat 9.6 IntPtLon 10.6 LSADC $2. @332 PartFlag $1. (SDElm SDSec SDUni)($5.) TAZ $6. UGA $5. PUMA5 $5. PUMA1 $5. @384 MACC $char5. UACP $char5. ; geo_id+1; if cnty ne ' ' then County=state||cnty; *--edit the tract so that it is in xxxx.xx format with leading and trailing zeroes--; if TractIn ne ' ' then Tract=translate( substr(TractIn,1,4)||'.'||substr(TractIn,5,2) ,'0',' '); drop tractin; select(SumLev); *---Assign the standardized Geographic Code to uniquely ID the geographic area--; when('010') geocode=' '; when('020') geocode=region; when('030') geocode=division; when('040') geocode=state; when('050') geocode=county; when('060') geocode=%concatd(county,cousubfp); when('070') geocode=%concatd(county,cousubfp,placefp); when('080') geocode=%concatd(county,cousubfp,placefp,tract); when('091') geocode=%concatd(county,cousubfp,placefp,tract,aianhhfp,anrc,cd106,bg); ***????***; when('101') do; geocode=%concatd(county,tract,block); end; when('140') geocode=%concatd(county,tract); when('144') geocode=%concatd(county,tract,aianhhfp); when('150') geocode=%concatd(county,tract,bg); when('154') geocode=%concatd(county,tract,bg,aianhhfp); when('155') do; geocode=%concatd(county,placefp); *<===Override areaname to make it the name of the place rather than the county.To leave as-is delete this + next 4 lines; length _arg $7; _arg=state||placefp; drop _arg; areaname=put(_arg,$fplace.); if areaname=_arg then areaname='Place '||placefp; end; when('158') geocode=%concatd(state,placefp,cnty,tract); when('160') geocode=%concatd(state,placefp); when('170') geocode=%concatd(state,concit); when('172') geocode=%concatd(state,concit,placefp); when('280','283','286') geocode=%concatd(state,aianhhfp); when('282','285','288') geocode=%concatd(state,aianhhfp,cnty); when('261','265','267') geocode=%concatd(state,aianhhfp,cnty,cousubfp); when('263','266','268') geocode=%concatd(state,aianhhfp,cnty,cousubfp,placefp); when('281','284','287') geocode=%concatd(state,aianhhfp,aits); when('230') geocode=%concatd(state,anrc); when('390') geocode=%concatd(state,msacmsa); when('391') geocode=%concatd(state,msacmsa,placefp); when('392') geocode=%concatd(state,msacmsa,cnty); when('393') geocode=%concatd(state,msacmsa,cnty,cousubfp); when('395') geocode=%concatd(state,msacmsa,pmsa); when('396') geocode=%concatd(state,msacmsa,pmsa,cnty); when('397') geocode=%concatd(state,msacmsa,pmsa,cnty,cousubfp); when('374') geocode=%concatd(state,necma); when('375') geocode=%concatd(state,necma,placefp); when('376') geocode=%concatd(state,necma,cnty); when('500') geocode=%concatd(state,cd106); when('510') geocode=%concatd(state,cd106,cnty); when('511') geocode=%concatd(state,cd106,cnty,tract); when('521') geocode=%concatd(state,cd106,cnty,cousubfp); when('531') geocode=%concatd(state,cd106,placefp); when('541') geocode=%concatd(state,cd106,concit,placefp); when('550','551','552') geocode=%concatd(state,cd106,aianhhfp); when('553','554','555') geocode=%concatd(state,cd106,aianhhfp,aits); when('851') geocode=%concatd(state,zcta3); when('852') geocode=%concatd(state,zcta3,cnty); when('871') geocode=%concatd(state,zcta5); when('881') geocode=%concatd(state,zcta5,cnty); otherwise do; if sumlev ne lag(sumlev) then do; _badsl+1; drop _badsl; if _badsl le 50 then put '**Unrecognized SUMLEV: ' sumlev; end; end; end; *--select group--; geocode=compress(geocode,' '); *--remove any blanks from geocode-----------------(mod 4.21.01)---; *--Create land and total area values in square miles. --; LandSQMI=AreaLand/2589988; AreaSQMI=LandSQMI + (AreaWatr/2589988); format LandSQMI AreaSQMI 9.2; format IntPtLon 11.6 IntPtLat 10.6; *<--added 7-13-01-; label SumLev='Geographic Summary Level' GeoComp='Geographic Component'; label cnty='County code'; label LandSQMI='Land Area Sq Mls' AreaSQMI='Total Area Sq Mls' AreaLand='Land Area Sq Meters' AreaWatr='Water Area Sq Meters'; label cd106='Cong District - 106th (1998)' sldu='State Leg District Upper Chbr' sldl='State Leg District Lower Chbr'; label ZCTA5='ZIP Census Tabulation Area'; if sumlev='101' then output blks; else output geos; run; proc sort data=geos out=sasout.&stab.geos(label="Geo Hdrs Except for Blocks" index=(SumLev) compress=yes); by sumlev geocode; run; proc sort data=blks out=sasout.&stab.blks(label="Block Hdrs" index=(county) compress=yes); by county tract block; run; data _null_; file stdout; put "Processing complete for &statenm"; run; filename geos clear; %mend doit; %dostates(n=51,names=1,msgs=1)