x cd /pub/data/georef/Tools; %let pgm=cbsas09; filename pgm "&pgm..sas"; *--create data sets with info regarding Core Based Statistical Areas (Micropolitan and Metropolitan Statistical Areas as posted on Bureau site as of December, 2009. (Being run 9-27-10) *************** See http://www.census.gov/population/www/estimates/metrodef.html for original source of these data. Running with latest (2009) estimates data. *******After this run the mocbsasYY_webrepts.sas *******Update https://mcdc.missouri.edu/reports/geography/index.html to update references to the latest reports as generate here. --*; %let setsfx=; *<---------use 2-digit latest year as value while testing. Set to null for final run. Allows us to generate new versions of these datasets without initially replacing the old ones.----------; %let cbsayr=2009; %let month=Dec; %let popestyr=09; *<--- we get population estimates and msacmsa/pmsa codes from popests.uscom&popestyr --; %let pyr=%eval(&popestyr - 1); filename in '../metrodefs.dec2009'; *<------downloaded from http://www.census.gov/population/www/metroareas/lists/2000/List1.txt 09/10 ---; filename csain '../csacomps.dec2009.txt'; *<--downloaded from http://www.census.gov/population/www/metroareas/lists/2009/List6.txt 09/10 ---; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; libname user '/SAS_temp/userb'; * options nofmterr; /* =======WE RUN THIS STEP ONLY ONCE IN INTERACTIVE MODE. THE LOG NOTES ARE THEN INSERTED AS COMMENTS BELOW *---We begin by first renaming all the current versions using a 2-digit year suffix to identify them as being an earlier version.----; proc datasets library=georef nolist; change metrodivs=metrodivs08; change csacbsas=csacbsas08; change cbsas=cbsas08; change cbsacos=cbsacos08; change cbsapops=cbsapops08; quit; NOTE: Changing the name GEOREF.METRODIVS to GEOREF.METRODIVS08 (memtype=DATA). NOTE: Changing the name GEOREF.CSACBSAS to GEOREF.CSACBSAS08 (memtype=DATA). NOTE: Changing the name GEOREF.CBSAS to GEOREF.CBSAS08 (memtype=DATA). NOTE: Changing the name GEOREF.CBSACOS to GEOREF.CBSACOS08 (memtype=DATA). NOTE: Changing the name GEOREF.CBSAPOPS to GEOREF.CBSAPOPS08 (memtype=DATA). ===============END STEP/COMMENT=============================================== */ title "&pgm: Create georef Data Sets Related to Core Based Statistical Areas, &month, &cbsayr"; data cbsas( keep=cbsa AreaName cbsatype Year) metrodivs(keep=cbsa cbsaname MetroDiv AreaName Year) cbsacos(keep=stab state cnty county fipco cbsa cbsatype cbsaname metrodiv Year); infile in end=last dsd truncover firstobs=8 ; length CBSA $5 MetroDiv $5 county $5 Level $10 AreaName $80 cbsaname $5; length fipco cbsatype $5 State Stab $2 cnty $3; retain Year "&cbsayr"; *input cbsa -- AreaName @; input cbsa $5. @; if length(cbsa)=5 and verify(cbsa,'0123456789')=0; *---look for lines with 5-digit numerics in cols 1-5--; input MetroDiv $9-13 county $17-21 AreaName $25-99 ; if length(county)=5 then level='Component'; else if length(MetroDiv)=5 then level='Division'; else level='cbsa'; select (Level); when ('cbsa') do; if index(areaname,'Metropolitan ') then cbsatype='Metro'; else if index(areaname,'Micropolitan ') then cbsatype='Micro'; else do; cbsatype='?????'; put _all_; end; retain cbsatype; output cbsas; end; when ('Division') do; cbsaname=cbsa; output metrodivs; end; when ('Component') do; fipco=county; format county $county.; State=substr(county,1,2); Stab=put(state,$fipstab.); cnty=substr(county,3,3); cbsaname=cbsa; format cbsaname $cbsa.; *<---associate a format code with this so it prints the name.--; if not( cbsa='41180' and county='29055') then output cbsacos; *<----we omit the Crawford county entry for the St Louis metro area. Bogus--; end; otherwise do; put 'cbsatype not recognized: ' level _n_= / _infile_; delete; end; end; proc sort data=metrodivs out=georef.metrodivs&setsfx(index=(metrodiv) label="Metropolitan Divisions as of &month, &cbsayr"); by cbsa metrodiv; run; *---read the file with CSA definitions and names to create the csacbsa dataset------------------*; data georef.csacbsas&setsfx(label="Combined Statistical Areas and CBSA Components, &month, &cbsayr"); infile csain firstobs=7 truncover; length csa $3 cbsa $5 CSAName $96 CBSAName namein $96 cbsatype $5; input csa $1-3 cbsa $6-10 namein $13-88; retain CSAName; if csa ne ' ' and verify(csa,'0123456789')=0; *--must be 3-digit value---; if cbsa=' ' then do; csaname=namein; delete; end; else do; if not (length(cbsa)=5 and verify(cbsa,'0123456789')=0) then put /'****error***** ' _all_ / _infile_; cbsaname=namein; if index(namein,'Metropolitan Stat') then cbsatype='Metro'; else cbsatype='Micro'; output; end; drop namein ; run; proc sort data=georef.csacbsas&setsfx; by csa cbsa; run; proc datasets nolist library=georef; modify csacbsas&setsfx; index create csa; index create cbsa; quit; proc sort data=cbsas; by cbsa; run; data georef.cbsas&setsfx(index=(cbsa) label="Core Based Stat Areas &month, &cbsayr"); merge cbsas(in=incbsas) georef.csacbsas&setsfx(keep=cbsa csa); by cbsa; run; *----Generate $cbsa, $csa and $metrodiv permanent format codes----; filename text '/pub/sas/formats/Scbsa.sas'; filename text2 '/pub/sas/formats/Smetrodiv.sas'; filename text3 '/pub/sas/formats/Scsa.sas'; %genfmat(setin=georef.cbsas&setsfx,argvars=cbsa,labelvar=areaname,labellen=80,arglen=5,fmatname=cbsa,savedoc=1); %genfmat(setin=georef.metrodivs&setsfx,argvars=metrodiv,arglen=5,labelvar=areaname,labellen=80,fmatname=metrodiv, textfile=text2,savedoc=1); proc sql; create table csanames as select distinct csa, csaname from georef.csacbsas&setsfx ; quit; %genfmat(setin=user.csanames,argvars=csa,arglen=3,labelvar=csaname,labellen=96,fmatname=csa,textfile=text3,savedoc=1); *---Merge population and 2000 msacmsa and pmsa codes from our popests dataset, July, 20&popestyr vintage, with the county level set. Starting with the 2004 version we keep a complete set of popjl&yy estimates---; proc sort data=cbsacos; by county; run; data georef.cbsacos&setsfx(label="County components of MSAs and Micropolitan SAs as of &month, &cbsayr"); merge cbsacos(in=incbsacos) popests.uscom&popestyr(keep=state county sumlev msacmsa pmsa necma Popcen2k PopJL: where=(sumlev='050') in=inests); by county; fipco=county; if not inests and state ne '72' then do; ***====No estimates data for Puerto Rico===; file log; put '**No estimates data for this county** ' fipco= county= ; end; cbsaname=cbsa; format cbsaname $cbsa.; Year="&cbsayr"; label county='County'; run; proc datasets nolist library=georef; modify cbsacos&setsfx; index create county; index create state; index create cbsa; quit; proc print data=georef.cbsacos&setsfx(obs=50); title2 "georef.cbsacos&setsfx"; by state; id county; run; proc print data=georef.cbsas&setsfx(obs=50); title2 "georef.cbsas&setsfx"; id cbsa; run; *---------------Generate a web report showing the data for Missouri --------; ods listing close; ods printer pdf style=sasweb file="/pub/reports/geography/mocbsas&setsfx..pdf" notoc; options nodate; *---create report file where we combine codes and names into single fields--; data report; set georef.cbsacos&setsfx(rename=(cbsa=cbsacode) drop=county); where state='29' or put(cbsacode,$cbsa.) contains("MO") ; if cbsacode ne ' '; length CBSA $100 County $40; cbsa=cbsacode||' '||put(cbsacode,$cbsa.); County=fipco|| ' '|| put(fipco,$county.); keep cbsa county popcen2k popjl&popestyr; format popjl&popestyr comma11.; run; proc sort data=report; by cbsa county; run; proc print data=report label; title 'Missouri Core Based (Metropolitan and Micropolitan) Statistical Areas (CBSA''s)'; title2 "County Components as Defined by OMB, &month &cbsayr"; title3 .h=.8 'Report Shows CBSA''s Entirely or Partially Within Missouri'; footnote .h=.7 "Generated by &pgm..sas in georef/Tools on &sysdate"; footnote2 .h=.7 "Pt of Sullivan City in Crawford co. is in St. Louis MSA But Not Shown Here"; by cbsa ; id cbsa; var county Popcen2k PopJL&popestyr; sum PopCen2k PopJL&popestyr ; label Popcen2k='Census 2k Pop' Popjl&popestyr="July 20&popestyr Pop Est"; run; ods printer close; *-------Summarize pops by cbsas. DO NOT RUN THIS STEP UNTIL OTHERS ARE DEBUGGED---------------*; proc sort data=georef.cbsacos&setsfx(keep=cbsa cbsatype cbsaname popcen2k popjl&popestyr county) out=cbsacopops; by cbsa; run; data georef.cbsapops(label='Census 2000 and latest Population Estimates for CBSAs' compress=yes); set cbsacopops; by cbsa; where cbsa ne ' '; *<---filter added 5-12-10 to get rid of this big hunk of non-CBSA counties--; length Counties $800; retain Counties; label Counties='Counties that comprise the CBSA'; if first.cbsa then do; counties=put(county,$county.); _Pop2k=Popcen2k; _popest=Popjl&popestyr; end; else do; counties=trim(counties)||', '||put(county,$county.); _pop2k + popcen2k; _popest + Popjl&popestyr; end; if last.cbsa then do; popcen2k=_pop2k; Popjl&popestyr=_popest; output; end; format popcen2k Popjl&popestyr comma11.; drop _: county; run; ods printer pdf style=sasweb file="/pub/reports/geography/metropops&popestyr..pdf" NOTOC; ods listing close; options nodate; Title "Populations of Metropolitan Statistical Areas for US: 2000 Census and July, 20&popestyr Estimate"; proc print data=georef.cbsapops(where=(cbsatype='Metro')) label uniform; id cbsaname; var cbsa counties popcen2k popjl&popestyr; label cbsaname='Metropolitan Area' cbsa='CBSA Code' popcen2k='2000' popjl&popestyr="20&popestyr"; format popcen2k popjl&popestyr comma11.; footnote .h=.7 "Generated by &pgm..sas in georef/Tools from data in georef.cbsapops on &sysdate"; footnote2 .h=.7 'Source; U.S. Bureau of the Census and the Federal State Coop for Population Estimates'; footnote3 .h=.7 "Core Based Statistical Areas are as defined on &month, &cbsayr"; footnote4 .h=.7 "Companion Report for Micropolitan Areas is in micropops&popestyr..pdf"; run; ods pdf close; Title "Populations of Micropolitan Statistical Areas for US: 2000 Census and July, 20&popestyr Estimate"; ods printer pdf style=sasweb file="/pub/reports/geography/micropops&popestyr..pdf" NOTOC; proc print data=georef.cbsapops(where=(cbsatype='Micro')) label uniform; id cbsaname; var cbsa counties popcen2k popjl&popestyr; label cbsaname='Micropolitan Area' cbsa='CBSA Code' popcen2k='2000' popjl&popestyr="20&popestyr"; format popcen2k popjl&popestyr comma11.; footnote .h=.7 "Generated by &pgm..sas in georef/Tools from data in georef.cbsapops on &sysdate"; footnote2 .h=.7 'Source; U.S. Bureau of the Census and the Federal State Coop for Population Estimates'; footnote3 .h=.7 "Core Based Statistical Areas are as defined in &month, &cbsayr"; footnote4 .h=.7 "Companion Report for Metropolitan Areas is in metropops&popestyr..pdf"; run; ods pdf close;