x cd /pub/data/mable14/Tools; %let pgm=molibdists; filename pgm "&pgm..sas"; *---Create the MO library districts special dataset to be incoporated into the mable app using v14 data. July, 2015. Processing by jgb, OSEDA, part of MCDC project. ---*; filename csvin "../molibdists2k.csv"; *--generated using mable2k web app. Links molibdists to county--; filename text "/pub/sas/formats/Slibd15_.sas"; libname corrlst "/pub/data/corrlst"; libname mable14 "/pub/data/mable14"; filename recodes "/pub/sas/formats/libdist15_cnvtfmats.sas"; %**let corrlstname=mobl2libdst2015; ***********We changed things between June and September processing. In June the corrlst data set we created attempted to have split 2010 blocks with allocation factors. But in Sept we decided that was not working because the units we got from GRC were not blocks but split blocks with suffixes. So on 9-26-15 we reran the setup moblktolibdist2015.sas in corrlst/Tools and created a new set corrlst.moblktolibdist2015 (name is similar to previous but replaces "2" to "to" and "libdst" to "libdist"). This simplifies things somewhat. Maybe. Step 2 here is the Sept version. ************; proc format; %include recodes; *--defines 2 table lookup format codes: $ldcnvt converts GRC codes to new dist codes w names, $libd05c converts old lib dist codes (vintag 2005) to new codes and names. Only using the first one, for now. -------; proc format ddname=work cntlout=sasfmts(keep=fmtname start label); run cancel; *---We decided we did not need to do this.--; /*<=========================Comment out===================================== *------------Step 1: Store historical related data for consistency. The codes used in 2000 version.----; data molibdists2k(label="MO Library Districts as defined for mable2k + primary County Codes"); infile csvin dsd missover firstobs=3; length libcode2k $3 pcounty2k $5 _cntyname $32 libname2k $64 pop2k afact 4; input libcode2k--afact; if libcode2k='999' then delete; proc sort; by libcode2k afact; run; data mable14.molibdists2k(label="MO Library Districts as defined for mable2k + primary County Codes"); set molibdists2k; by libcode2k; if last.libcode2k; *--largest afact so we have the primary county--; label afact='Portion of libdist in pcounty2k'; format afact 5.3; run; ===========================End commented out================================ */ *---------Step 2: Copy the block level equiv file from corrlst to here and edit Distname---; *----In rerun of Oct 1 we add code to create a differebt value for libdcode, replacing the arbitrary codes provided by GRC. Terry B. provided these names by taking a coding template file we provided and he edited to contain the new codes. This is captured in the recodes file, defining 2 sas format tables.--; options compress=Yes; data mable14.moblk2libdist(label="As of 2015 per GRC Extract" sortedby=county tract block); set corrlst.moblktolibdist2015 (drop=libdist); length State $2 cnty $3 DistName $64 newlibdcode $9; if subdist='NA' then subdist=' '; State=substr(county,1,3); cnty=substr(county,3,3); Distname=district; if subdist ne ' ' and subdist ne 'NA' then distname=trim(district)||' - '||subdist; drop district subdist; *----assign the new library district codes including converting all the NAs to 999--------------; length _lookup $60; _olddistname=distname; *--so we can verify that it does not change--; _lookup=put(libdcode,$ldcnvt.); if _lookup='NA' then do; newlibdcode='MO9999'; *<----Is this what we really want? ---; end; else do; newlibdcode=scan(_lookup,1,' '); if length(newlibdcode)=6 then Distname=substr(_lookup,8); else if length(newlibdcode)=9 then Distname=substr(_lookup,11); else abort abend; end; if distname ne _olddistname then do; put '**Name changed: ' libdcode= newlibdcode= _olddistname= distname=; end; drop _: ; rename libdcode=libcdgrc newlibdcode=libdcode; label libdcode="Lid dist code assigned by GRC 6/15"; run; *----Lets look at codes and names only without the block detail----; proc sql; create table distcodes as select distinct libdcode, distname from mable14.moblk2libdist ; quit; data _null_; set distcodes; by libdcode; if not (first.libdcode and last.libdcode); put _all_; run; proc print data=distcodes; run; %genfmat(argvars=libdcode,arglen=9,labelvar=distname,labellen=64,fmatname=libd15_,fmatlib=mable14); run; options fmtsearch=(mable14 sasctlgs work); data _null_; format d $libd15_.; d='MO0001'; put d=; d='MO9999'; put d=; run;