x cd /pub/data/corrlst/Tools; %let pgm=zip4_blocks; filename pgm "&pgm..sas"; *--Read the tiger 2000 "ua" files to generate a correlation list linking zip4s to census blocks, corrlst.mozip4blks (for now just doing Mo as feasibility test) ---; *--John Blodgett, April, 2003. --*; libname corrlst '/pub/data/corrlst'; libname user "/SAS_temp/user"; %macro doside(sd); if cnty&sd > '000' then do; side="&sd"; county=state&sd||cnty&sd; zip=zip&sd; tract=substr(tractin&sd,1,4)||"."||substr(tractin&sd,5,2); block=block&sd; output; end; %mend doside; %macro doit(county,cntyname); filename in1 pipe "unzip -pa /pub/data/tigerua/TGR&county..ZIP TGR&county..RT1"; filename Zin pipe "unzip -pa /pub/data/tigerua/TGR&county..ZIP TGR&county..RTZ"; proc datasets nolist library=user; delete rtzcodes rt1codes merged; quit; *---build a dataset with the RT1 data, one obs per side of the segment, avoiding "out" sides--; data rt1codes; infile in1 lrecl=228; input rt $1 tlid 6-15 @131(statel stater)($2.) (cntyl cntyr)($3.) @107 (zipl zipr)($5.) @171 (tractinl tractinr)($6.) (blockl blockr)($4.) @191 (frlong frlat tolong tolat)(10.6 9.6); length side $1 county $5 zip $5 tract $7 block $4 long lat 8; format long 11.6 lat 10.6; keep tlid side county zip tract block long lat; if rt ne '1' then do; put 'Record type is not 1! --- aborting...' / _all_; list; stop ; end; long=(frlong+tolong)*.5; lat=(frlat+tolat)*.5; *--average the coordinates of the end points-; %doside(l); %doside(r); run; proc sort data=rt1codes; by tlid side; run; *---build a set using the Z record with ZIP+4 codes---; data rtzcodes; infile Zin; input rt $1 tlid 6-15 rtsq 3. zip4l $4. zip4r $4.; if rtsq=0; drop rtsq; side='l'; zip4=zip4l; link output; side='r'; zip4=zip4r; link output; return; output: if right(zip4) ne ' 0' then output; return; keep tlid side zip4; run; proc sort data=rtzcodes; by tlid side; run; data merged; length zip $5 zip4 $4; *<--make these arg variables go first--; merge rt1codes(in=inrt1) rtzcodes(in=inrtz); by tlid side; length nsegs 5; nsegs=1; if inrtz; *---will be very interesting to see how many rt1code obs have matching rtz codes--; if not inrt1 then do; put '***no RT1 data for this RTZ record: ' tlid= side= zip4=; delete; end; run; proc sort data=merged out=zb&county; by zip zip4 county tract block; run; %mend doit; %***docos(state=29) ; %let setlist=; %macro coset(county,cntyname); %let setlist=&setlist zb&county; %mend coset; %docos(mac=coset) %put setlist= &setlist; data setinv/view=setinv; set &setlist; ; by zip zip4; run; %corrwt(setin=setinv, setout=corrlst.mozip4blks, g1=zip zip4, g2=county tract block, weight=nsegs, keepwt=1, xyopt=latlon,latvar=lat,lonvar=long) run; %corrwt(setin=setinv, /* for now. We need to run this just once for the entire state in final run */ setout=corrlst.mozip4cos, g1=zip zip4, g2=county, weight=nsegs, keepwt=1, xyopt=latlon,latvar=lat,lonvar=long) run; proc print data=corrlst.mozip4cos(obs=200); by zip; id zip; title2 "Partial listing of output county level correlation list dataset"; run; proc print data=corrlst.mozip4blks(obs=200); by zip; id zip; title2 "Partial listing of output block level correlation list dataset"; run;