x cd /pub/sas/formats/Tools; %let pgm=genmocodes; filename pgm "&pgm..sas"; *--Generate a series of Missouri-only format codes to put names with named entities on the 2000 pl-94 file. Can be easily adapted to do similar work for other states by changing the value of the &state and &stab global parms. Note: The VTD codes on the Missouri geos file are pretty much a mess. Ryan says he knows. John Blodgett, OSEDA, U. of Missouri Outreach & Extension 3-2001. --*; %libname(pl942000); libname user '/SAS_temp/user'; %let state=29; %let stab=mo; /*<=========================Comment out===================================== *---This step was run to verify that cousupfp is unique within state and does not need to be county qualified-; proc sql; create table cousubs as select distinct cousubfp from pl942000.mogeos where sumlev='060'; create table cousubs2 as select distinct county, cousubfp from pl942000.mogeos where sumlev='060'; quit; ===========================End commented out================================ */ data cntys places mcds vtds; set pl942000.&stab.geos; where sumlev in ('040','050','060','700','160'); *--state, county, mcd, vtd and place---; length arg $9 label $40; label=areaname; select (sumlev); when('040') do; *--we include the state in the county format as a convenience--; arg=state; output cntys; arg=state||'999'; output cntys; end; when ('050') do; arg=county; %parseit(label,99); *--locate last word in string-; if _word='County' then substr(label,_locword)=' '; output cntys; arg=cnty; output cntys; end; when ('060') do; arg=cousubfp; output mcds; arg=state||cousubfp; output mcds; end; when ('160') do; arg=placefp; output places; arg=state||placefp; output places; end; when ('700') do; arg=county||vtd; label=tranwrd(label,'Voting District','VTD'); output vtds; arg=cnty||vtd; output vtds; end; otherwise do; put / '***Unexpected sumlev code: ' sumlev= / _all_; stop; end; end; *--select--; keep arg label sumlev; run; filename text "/pub/sas/formats/S&stab.cnty.sas"; %genfmat(setin=cntys,fmatname=&stab.cnty, arglen=5,argvars=arg,labelvar=label,labellen=16, other=' ',savedoc=0) run; filename text "/pub/sas/formats/S&stab.mcd.sas"; %genfmat(setin=mcds,fmatname=&stab.mcd, arglen=7,argvars=arg,labelvar=label,labellen=40, other=' ',savedoc=0) run; filename text "/pub/sas/formats/S&stab.fplace.sas"; %genfmat(setin=places,fmatname=&stab.fplace, arglen=7,argvars=arg,labelvar=label,labellen=40, other=' ',savedoc=0) run; filename text "/pub/sas/formats/S&stab.vtd.sas"; %genfmat(setin=vtds,fmatname=&stab.vtd, arglen=9,argvars=arg,labelvar=label,labellen=40, other=' ',savedoc=0) run; data test; county='29001'; put county= county $mocnty.; county='183'; put county= county $mocnty.; mcd='2904546'; put mcd= mcd $momcd.; mcd='04546'; put mcd= mcd $momcd.; place='2900244'; put place= place $mofplac.; place='00244'; put place= place $mofplac.; vtd='290012'; put vtd= vtd $movtd.; vtd='0012'; put vtd= vtd $movtd.; run;