x cd /pub/data/georef/Tools; %let pgm=mocogeos; filename pgm "&pgm..sas"; ******CAUTION!!! - setup uses a proc datasets step to create a mocogeos_old set which is then updated!!!!******; ***NOTE: On 9-13-02 WE EDITED THE RPC CODE FOR OSAGE COUNTY. We changed it from 10 to 08 (Meramec)-----; ***NOTE: On 1-12-06 WE EDITED THE RPC CODE FOR Pulaski COUNTY. We changed it from 06 to 08 (Meramec)-----; ***NOTE: On 4-23-08 WE EDITED THE 3 CBSA-related codes for Crawford COUNTY. It has been indicating it was in St Louis be it is NOT----; *--Read a CSV file created by the Geocorr app relating a number of higher level geographic codes to Missouri counties. Create georef.mocogeos--; ***Sep. 8, 2001: Adding variables fipco and DED_region, and pop2k. ***Nov. 19, 2001: Adding (keeping) SumLev and creating index on fipco. ***Jan. xx, 2002: Adding step to read the modot.txt file and add modot code. Code was added circa 1-8 and then inadvertently overwritten. We shall try to reproduce code here but new code re modot will NOT be tested! ***Nov. 3, 2004: Adding the ui_code (urban influence code) as well as cbsa and cbsatype as of 2003. We also drop 4 older codes, lma90, cz90, beale and msa95. March, 2007: After discovering an obsolete CBSA code for Clark county, updating these codes from latest source. --*; filename csvin '/pub/data/georef/moco_geocorr.csv'; filename modot '/pub/data/georef/modot.txt'; *--mo dept of transp district codes-; libname georef '/pub/data/georef'; libname corrlst '/pub/data/corrlst' access=readonly; %libname(sf12000x); /* data georef.mocogeos_old(replace=no); set georef.mocogeos; run ;*/ *<=========Create this backup interactively===; title "georef.mocogeos: High Level Geocodes for Missouri Counties"; *title2 "Revised November, 2004"; title2 "Revised January, 2006"; *<===============; footnote 'Report Produced by OSEDA, U. of Missouri Outreach and Extension'; /*<=========================Comment out===================================== proc format; VALUE $umx '908'=SE '918'=EC '928'=NE '938'=NW '948'=SC '958'=SW '968'=WC '978'=CE ; run; data georef.mocogeos(label='Mo County Geocodes'); length areaname $16.; infile csvin firstobs=2 dsd missover; length COUNTY $5 MSA90 $4 CZ90 $5 LMA90 $3 Beale $1 MSA95 $4 RPC $2 UMX $3 POP90 5 afact 5; input county--afact; if afact ne 1 then do; put '**Read error at line ' _n_ ; list; delete; end; length umx2 $2 cnty $3; if msa90='9999' then msa90=' '; umx2=put(umx,$umx2.); cnty=substr(county,3,3); retain state '29' ; label lma90='Labor Market Area, 1990' cz90='Commuting Zone, 1990' beale='Beale code' umx='U of Mo Extension Regn (Code)' umx2='Ext Region'; areaname=put(county,$county.); format pop90 comma7.; _ix=index(areaname,' MO'); if _ix then substr(areaname,_ix)=' '; if county='29510' then areaname='St. Louis City'; drop afact _ix; run; *--new step to read the dot codes from txt file--; data dotcodes; infile modot; length dot $2 county $5; input dot $ county $; if length(dot)=1 then dot='0'||dot; run; proc sort; by county; run; *---This step adds the variables SumLev, fipco and DED_region----; data georef.mocogeos(label='MO County level geographic codes' index=(fipco)); length fipco county $5 areaname $16. totpop pop90 5; *<---establish key variable order---; merge corrlst.mocodedrgns(in=inded) georef.mocogeos_old(in=inold) dotcodes(in=indot) sf12000x.moi(where=(sumlev='050') keep=county sumlev totpop in=insf1); by county; if not (inded and inold and insf1 and indot) then do; put /'****Error: Missing data for a county****' / _all_; abort abend; end; *--edit 2 counties with bad areanames--; if substr(areaname,16,1)='M' then substr(areaname,16,1)=' '; format DED_region $dedrgn.; format pop90 totpop comma9.; rename totpop=pop2k; label totpop='Total Pop, SF1, 2000 census'; label fipco='FIPS Code'; **drop sumlev; run; *---updates applied circa 11-03-04. We add ERS urban influence codes and cbsa-related codes and msacmsa2k---; data updates04; merge georef.us_erscodes(in=iners keep=fipco state ui_code) georef.cbsacos(in=incbsa keep=state fipco cbsa cbsaname cbsatype); by fipco; where state='29'; length msa2k $4; label msa2k='MSA code as of 2k census' cbsa='Core-based (metro/micro-politan) statistical area as of 12/03' UI_code='Urban influence code, 2003 (ERS)'; if not (iners and incbsa) then do; put '***Data missing? ' _all_; _nerr+1; if _nerr ge 5 then abort abend; drop _:; end; msa2k=put(fipco,$comet4.); run; proc print data=updates04 ; id fipco; run; data georef.mocogeos(label='Missouri County geocodes Updated 11/04'); update georef.mocogeos_old(in=inold) updates04(in=inups); by fipco; if not (inold and inups) then do; put //_all_; abort abend; end; drop CZ90 LMA90 msa95 Beale; *----We drop these seldom used rather obsolete codes----; run; ===========================End commented out================================ */ *---modify rpc code for Pulaski and create new field rpc02 with old rpc codes--- We ran an interactive step to copy the current mocogeos dataset to mocogeos_old prior to running this step--; data georef.mocogeos(label='Mo County Geocodes as of 01/06'); set georef.mocogeos_old; rpc02=rpc; label rpc='RPC code as of 2002'; label rpc='RPC code as of 01/06'; if county='29169' then rpc='08'; *--otherwise it retains its previous value--; if county='29045' then do; cbsa='22800'; cbsaname=cbsa; end; run; proc datasets library=georef nolist; modify mocogeos; index create county; quit; options ls=160 ps=120; proc print data=georef.mocogeos; by state sumlev; id fipco county; sum pop90 pop2k; title3 'Listing of the Dataset georef.mocogeos'; run; proc tabulate data=georef.mocogeos missing; *--some summary stats by various levels--; class msa2k cbsa rpc rpc02 ; var pop2k pop90; format msa2k $metro. cbsa $cbsa. rpc rpc02 $rpcname. ; table all='Missouri Totals' msa2k cbsa rpc rpc02, pop2k=' '*(n='# cntys'*f=5. sum='2000 Pop'*f=comma9.) pop90=' '*(sum='1990 Pop'*f=comma9.) ; title3 'Summaries for Various County-Based Regions'; run;