x cd /pub/data/georef/Tools; %let pgm=cnvt_erscountycodes; filename pgm "&pgm..sas" ; *---We convert the county typology codes as defined by the Economic Research Serive (ERS) at USDA. For background see http://maps.ers.usda.gov/new_rural/ . The ui_code from this dataset will be added to the georef.mocogeos dataset. jgb, 11/04. ---*; libname georef '/pub/data/georef'; filename uicodes '/pub/data/georef/urban_influence_codes_mo.csv'; filename ersccds '/pub/data/georef/erscountycodes_2004.csv'; filename text '/pub/sas/formats/Sui_code.sas'; *<---generate permanent format code source module--; title "&pgm: Create 2 georef data sets based on county codes from ERS, usda, circa 2004"; *---------------Step 1: read the CSV file to create the Missouri Urban Influence codes (UI_code)---; data georef.mouicodes(label='Mo Urban Influence Codes, circa 2004 form ERS'); infile uicodes firstobs=4 dsd ; length county $5 AreaName $32 UI_code $2 UI_code_label $80 _pop2k $12 pop2k 5; input county -- _pop2k; if length(ui_code)=1 then ui_code='0'||ui_code; label ui_code='Urban Influence code' ui_code_label='UI Code Label' pop2k='Total Pop, 2000 Census'; pop2k=compress(_pop2k,','); drop _:; fipco=county; length state $2; state=county; retain sumlev '050'; run; proc print data=georef.mouicodes; by state sumlev; id fipco; title2 'georef.mouicodes: Missouri Urban Influence Codes'; run; *-------------Step 2: From the dataset just created generate the $ui_code format--------------*; proc sort data=georef.mouicodes(keep=ui_code ui_code_label) nodupkeys out=uicodes; by ui_code; run; options mprint; *---We plan to post-edit this very short sas format source file to edit the labels down to 64 chars max--; %genfmat(fmatname=ui_code,argvars=ui_code,arglen=2,labelvar=ui_code_label,setin=uicodes,labellen=80) %include text /source2; *----On this run we recompile the format and show the edited values on the log--; run; *-------------Step 3: Create the US County Typology codes data set---------------------------*; data georef.us_erscodes(label='USDA ERS county typology codes circa 2003'); infile ersccds dsd firstobs=2 missover; length State $2 fipco $5 stab $2 AreaName $40 County $5 metro $1 UI_code $2 farm house loweduc lowemp perpov poploss rec retire $1; input fipco--areaname metro--retire; *-----------FIX ERROR in county code for Routt county, CO---; if fipco='81070' then fipco='08107'; if fipco lt lag(fipco) then do; put /'**County code not in ascending order at line ' _n_ fipco=; end; County=fipco; state=substr(county,1,2); if retire=' ' then do; put //'***Problem reading ersccds file: ' _all_ / _infile_; stop; end; if length(UI_code)=1 then UI_code='0'||UI_code; *--make it 2-digit with a leading 0--; label fipco='FIPS County Code'; label metro='Metro indicator, 2003: 0=No 1=Yes' farm='Farm-dependent indicator' house='Housing stress indicator' loweduc='Low education indicator' lowemp='Low employment indicator' perpov='Persisitent poverty indicator' poploss='Population loss indicator' rec='Nonmetro recreation area indicator' retire='Retirement destination indicator'; run; proc tabulate data=georef.us_erscodes; class state metro--retire; table state all, (metro UI_Code farm house loweduc lowemp perpov poploss rec retire)*f=4.; title2 'Frequencies by State from georef.us_erscodes'; format state $state.; * ui_code $ui_code.; run;