x cd /pub/data/corrlst/Tools; %let pgm=mobl2libd2010; filename pgm "&pgm..sas"; *----Create the 2010 census block to library district corrleation list using dbf file created by GRC, J. Harlan, 2013. . Outputs are: corrlst.&pgm corrlst.mobg2libd2010 (block group level c list, derived) georef.libdists13 (with assigned Distcode and DistrictName) $libdnamme. -- SAS format code, created from the above georef set using genfmat. jgb, mcdc contract work, June 2013. Adding code to generate BG level list 6-10-13. ----*; filename dbfin '../lib13-block10.dbf'; libname corrlst '/pub/data/corrlst'; libname georef '/pub/data/georef'; libname user '/SAS_temp/user'; filename format '/pub/sas/formats/Slibdname.sas'; *<--writing over previous version which was moved to $libd05_.sas --; libname sf12010x '/pub/data/sf12010x' access=readonly; title "Creating corrlst.&pgm : Missouri 2010 Block to Library District Corr List"; /* ========================begin comment==================================== *---Begin by converting the dbf file to a SAS dataset--; proc dbf db4=dbfin out=corrlst; run; *--This set has only 2 vars: libdist, the name of the district and relate the equiv of esriid, the block geocode-; proc sql; create table districts as select distinct libdist from corrlst order by libdist; run; proc sort data=corrlst(rename=(libdist=DistrictName)); by DistrictName; run; *---There are 166 library districts in 2013. Back in 2002 there were 166. ---------; data georef.libdists13(label='Missouri library districts as of 5/2013 with MCDC-generated Codes'); length Distcode $3 DistrictName $64; set districts; if libdist=' ' then delete; _nlib+1; distcode=put(_nlib,z3.); DistrictName=libdist; keep distcode DistrictName; run; *---And (re)create the $libdname format code that can be used to put the name with the code---; %genfmat(sasin=georef.libdists13,arg=distcode,labelvar=DistrictName,labellen=64,arglen=3, textfile=format,fmatname=libdname,runproc=0); run; libname sasctlgs clear; libname sasctlgs '/pub/sas/catalogs'; proc format library=sasctlgs; %include '/pub/sas/formats/Slibdname.sas'; run; data _null_; infile format; input; file print; put _infile_; title2 'Listing of $libdname format code'; run; *----Now get the just-created lib district code into the corrlst dataset and break down their relate variable (comparable to our esriid) into its components000; proc sort data=georef.libdists13 out=libdists; by DistrictName; run; proc sort data= sf12010x.moblocks(keep=county tract block totpop totpop00 ) out=moblks; by county tract block; run; data mobl2libd; length County $5 Tract $7 Block $4 Distcode $3; merge libdists(in=in1) corrlst(in=in2 ); by DistrictName; if not (in1 and in2) then do; if in2 and DistrictName=' ' then distcode='999'; else do; put /_all_; abort abend; end; end; county=substr(geoid10,1,5); tract=substr(geoid10,6,4)||'.'||substr(geoid10,10,2); block=substr(geoid10,12,4); drop geoid10 DistrictName; Distname=Distcode; format Distname $libdnam.; run; proc sort data=mobl2libd; by county tract block descending xfact; run; data corrlst.&pgm(label='MO 2010 Census Block to 2013 Library District'); merge mobl2libd (in=in1) moblks(in=in2); by county tract block; length primary 3; primary= first.block; label primary ='Flag: Primary district for this block?'; format county $5.; rename totpop=pop10; if not in2 then do; _nbad+1; drop _nbad; if _nbad le 100 then put _all_; else abort abend; end; *---The GRC filtered out all the blocks that were NA, i.e. not within any district---; if not in1 then do; DistCode='999'; Distname='NA'; end; run; proc contents data=corrlst.&pgm; proc print data=corrlst.&pgm(obs=100); by county; id tract block; title2 "Sample Listing of corrlst.&pgm"; run; ==========================end comment====================================== */ *---Now create the bg level corrlst----; %let bglist=mobg2libd2010; data mobl2distedited; set corrlst.&pgm; length BG $1; BG=substr(block,1,1); if xfact then pop10=xfact*pop10; drop totpop00 primary xfact; run; %corrwt(setin=mobl2distedited,setout=corrlst.&bglist, geocds1=county tract bg,geocds2=distcode,idvars=distname, weight=pop10,keepwt=1) proc print data=corrlst.&bglist(obs=100); title2 "First 100 Obs of corrlst.&bglist"; by county; id tract bg; run;