x cd /pub/data/corrlst/Tools; %let pgm=moblktolibdist2015; filename pgm "&pgm..sas"; *---Process the block to Library District equivalency file as provided 6-2015 by the GRC (Jason Hinsen)--; libname corrlst '/pub/data/corrlst'; filename dbfin "/pub/data/corrlst/CB2010LibDistsRelationship.dbf"; libname user '/SAS_temp/userb'; options compress=yes; /*<=========================Comment out===================================== ===========================End commented out================================ */ proc import datafile=dbfin out=user.&pgm dbms=dbf; run; data user.&pgm.edited; ** distlevel; *---We create some new keys and we drop some data that appears to be irrelevant to what we want to do----; length County $5 Tract $7 Block $4 district $80 subdist $24 libdcode $3 libdist $128; set user.&pgm(keep=fid_cb2010 geoid suffix District subdist type libdist fid_librar percentLib rename=(geoid=Ngeoid)); length geoid $16; geoid=ngeoid; drop ngeoid geoid; County=substr(geoid,1,5); ***if county in ('29017','29123'); *<======Bollinger and Madison cos--; Tract=substr(geoid,6,4)||'.'||substr(geoid,10,2); Block=substr(geoid,12,4); *---We decide not to mess with afact calculation. We are not splitting blocks so all we do is take the obs with highest value of percentlib and allocate entire block to that district.---; *if percentLib < .09 then delete; *if percentlib > 99.9 then afact=1.0; *else afact=percentLib*.01; *format afact 5.3; *label afact="Block to libdist alloc factor"; *drop percentLib; informat ; *<---want these all to go away. Proc import creates ridiculous things---; format district libdist subdist type ; libdcode=put(FID_Librar,z3.); drop FID_:; *--drop the numeric libdist code and the block code--; rename SUFFIX=SFX; run; proc sort; by county tract block percentlib; run; options ls=160; title2 ; data corrlst.&pgm (label='2010 blk to library dist' ) notmatched; merge sf12010x.moblocks(in=insf1 keep=county tract block totpop areasqmi) user.&pgm.edited(in=ingrc); by county tract block; if last.block; *---because of sort this is match with largest percentlib value.----; if not (insf1 and ingrc) then output notmatched; else output corrlst.&pgm; format totpop 5.; label totpop='Pop 2010 Census'; label percentlib='% of split block (largest value for block)'; *--not explained well but its a clue... --; informat _character_ ; run; proc print data=notmatched n; by county; id tract block; title2 "Unmatched blocks"; run; options ls=160; ods html file="&pgm" style=sasweb; proc tabulate data = corrlst.&pgm ; title2 "Tabulated by District and LibDist"; class district libdist libdcode; var totpop ; table all libdcode*libdist district, totpop*(n="nblks"*f=6. sum="TotPop"*f=comma7.); run; ods html close; proc contents data=corrlst.&pgm; run;