/* Mon Mar 14 09:xx:xx cST 1994, jgb */ /* This file converts a "bna" file to a SAS GMAP dataset */ /* Parameters set to make block groups on stat1 */ /* Values of &lpolid to be used for values of &polid: polid lpolid ------ ------ blk 16 census blocks: county(5)+tract(7)+blk(4) blkgrp 13 block groups: county(5)+tract(7)+bg(1) tract 12 census tracts (BNA's): county(5)+tract(7) county 5 includes state, e.g. 20001. fmcd 10 FIPS MCD: county(5)+fmcd(5) fplace 10 FIPS place: county(5)+fplace(5) tract80 12 1980 census tract: county(5)+tract80(7) mcd80 8 1980 MCD: county(5)+mcd80(3) ---------------- Use %LET statements below to specify parameters of conversion. This example converts a county file for state of Kansas. */ /* Following filename with pipe option can be used to directly access ZIPed files on systems that support piping. It is "commented out" in this sample run: filename bnafile pipe 'unzip -cqq /homed/blockgroups/bg20bna.zip bg20.bna'; */ *<====edit this filename statement.=========; filename bnafile '/homed/blockgroups/bg20.bna' ; %LET BNAFILE=bnafile; *<====Specifies fileref for BNA input file==; libname bg '/homed/blockgroups'; %LET SASOUT=bg.bgbounds; *<=Specifies name of output data set==; %LET POLID=blkgrp; *<====see table of values above====; %LET LPOLID=13; *<====see table again====; %LET PTSPERLN=3; *<===Number of x,y coord prs per line. This is fixed; *<===until and unless we ever decide to change it; %LET MAXPOLS=999999; *<====Maximum number of polygons to process===; *<====Use for test runs; %LET DEBUG=0; *<===Set to 1 to trigger diagnostic PUT statements==; *<===========temporary debug settings============================; /* %let debug=1; %let maxpols=2; */ TITLE 'Make Kansas Block Group boundary file'; OPTIONS NOMLOGIC MPRINT NOCENTER; DATA &SASOUT(KEEP=&POLID X Y SEGMENT); LENGTH &POLID $&LPOLID; LENGTH X Y 5 SEGMENT 3; FORMAT X Y 10.6; retain debug &debug; file print; INFILE &BNAFILE LENGTH=_L ; /* DELIMITER=' ,"'*/ LINK READHDR; if debug then PUT "RETURN FROM LINKHDR WITH &POLID= " &POLID +1 NPTS=; DO IPT=1 TO NPTS; LINK READXY; if debug=2 then put ipt= +1 x 10.6 +1 y 10.5; IF NOT (IPT=NPTS AND SEGMENT GT 1) THEN OUTPUT; IF IPT=1 THEN DO; X1=X; Y1=Y; END; ELSE IF X=X1 AND Y=Y1 THEN DO; SEGMENT+1; X1=X; Y1=Y; END; END; RETURN; READHDR: _npols+1; if _npols gt &maxpols then stop; INPUT HDRLINE $VARYING80. _L; HDRLINE=COMPRESS(HDRLINE,'"'); HDRLINE=COMPRESS(HDRLINE,'0D'X); *<===un-zipping adds these===; if debug then PUT HDRLINE=; &POLID=SCAN(HDRLINE,1,','); HDRLINEB=LEFT( REVERSE(HDRLINE)); NPTS=REVERSE(SCAN(HDRLINEB,1,',')); if debug then PUT &POLID= NPTS= / _INFILE_; SEGMENT=1; _N=.; RETURN; READXY: *---PARSE THE LINE WITH &PTSPERLN X-Y PAIRS ---; IF _N=&PTSPERLN OR _N=. THEN _N=1; ELSE _N+1; IF _N=1 THEN DO; IX=1; INPUT DLINE $VARYING80. _L; DLINE=COMPRESS(DLINE,'0D'X); END; ELSE IX+2; X=SCAN(DLINE,IX,' ,'); Y=SCAN(DLINE,IX+1,' ,'); RETURN; run; *<=========optional step to list some observations from output set==; proc print data=&sasout(obs=100); by &polid; id &polid; title2 "First 100 obs on &SASOUT"; run;