x cd /pub/data/georef/Tools; %let pgm=cbsas03; filename pgm "&pgm..sas"; *<===This setup was run in 2003 to create the original June 03 datasets. But they changed these again in December 03 (per OMB bulletin released in Feb. 04. So we need to get that data from the Bureau and regenerate everything. That will be a different setup, stored in cbsas03d *===Rerunning this in March of 2012 to put back a cbsas03 data set. ********; *--create data sets with info regarding Core Based Statistical Areas (Micropolitan and Metropolitan Statistical Areas as posted on Bureau site June 2003. From a spreadsheet created by R. Williams et al at MISER. Generates the web report webrepts/geography/mocbsas.pdf. jgb, June, 2003. Found a bug in the cbsapops dataset (and thus in the web reports generated from it) - we were not properly aggregating the 02 estimates when a cbsa was composed of multiple counties. Rerunning 7-19-04. --*; %let cbsayr=2003; %let popestyr=09; *<--- we get population estiamtes and msacmsa/pmsa codes from popests.uscom&popestyr --; *<========the old popests.uscom03 set was no longer available. So we go with more recent estimates.=============; filename in '../cbsas2003.csv'; filename csain '../combinedareas2003.csv'; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; ***libname user '/SAS_temp/userb'; options nofmterr; title 'Create georef Data Sets Related to Core Based Stat Areas, 2003'; 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 E $1 AreaName $80 cbsaname $5; *--The variable E is an empty column in the spreadsheet between level and areaname--; length fipco cbsatype $5 State Stab $2 cnty $3; retain Year "&cbsayr"; input cbsa -- AreaName @; select (Level); when (' ') delete; when ('Micro Area','Metro Area') do; cbsatype=scan(Level,1); retain cbsatype; output cbsas; end; when ('Division') do; input Areaname; 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.--; output cbsacos; end; otherwise do; put 'cbsatype not recognized: ' level _n_= / _infile_; delete; end; end; proc sort data=metrodivs out=georef.metrodivs03(index=(metrodiv) label='Metropolitan Divisions 2003 '); by cbsa metrodiv; run; data georef.csacbsas03(label='Combined Statistical Areas and CBSA Components, 2003' ); infile csain dsd firstobs=7; length csa $3 cbsa $5 Level $9 CSAName $96 CBSAName namein $96 cbsatype $5; input csa cbsa level _dum namein cbsaname; retain CSAName; if level='Combined' then do; csaname=namein; delete; end; else if level=:'M' then do; cbsatype=level; output; end; drop namein _dum level; run; proc sort data=georef.csacbsas03; by cbsa csa; run; proc sort data=cbsas; by cbsa; run; data georef.cbsas03(index=(cbsa) label='Core Based Stat Areas 2003 '); merge cbsas(in=incbsas) georef.csacbsas03(keep=cbsa csa); by cbsa; run; /* ========================begin comment==================================== *----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,argvars=cbsa,labelvar=areaname,labellen=80,arglen=5,fmatname=cbsa,savedoc=1); %genfmat(setin=georef.metrodivs,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 ; quit; %genfmat(setin=user.csanames,argvars=csa,labelvar=csaname,labellen=96,fmatname=csa,textfile=text3,savedoc=1); ==========================end comment====================================== */ *---Merge population and 2000 msacmsa and pmsa codes from our popests dataset, July, 20&popestyr vintage, with the county level set.---; proc sort data=cbsacos; by county; run; data georef.cbsacos03; merge cbsacos(in=incbsacos) popests.uscom&popestyr(keep=state county sumlev msacmsa pmsa necma Popcen2k PopJL&popestyr 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 cbsacos03; index create county; index create state; index create cbsa; quit; proc print data=georef.cbsas03(obs=50); title2 'georef.cbsas03'; id cbsa; run; proc print data=georef.cbsacos03(obs=50); title2 'georef.cbsacos03'; by state; id county; run; options nosource; /* ========================begin comment==================================== *---------------Generate a web report showing the data for Missouri --------; ods listing close; ods printer pdf style=sasweb file='/pub/reports/geography/mocbsas03.pdf'; options nodate; *---create report file where we combine codes and names into single fields--; data report; set georef.cbsacos03(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 comma9.; 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, June, 2003'; title3 .h=.8 'Report Shows CBSA''s Entirely or Partially Within Missouri'; footnote .h=.7 "Generated by cbsas03.sas in georef/Tools on &sysdate"; by cbsa ; id cbsa; var county Popcen2k PopJL&popestyr; label Popcen2k='Census 2k Pop' Popjl&popestyr="July 20&popestyr Pop Est"; run; ods printer close; *-------Summarize pops by cbsas (added 1/04)---------------*; proc sort data=georef.cbsacos03(keep=cbsa cbsatype cbsaname popcen2k popjl&popestyr county) out=cbsacopops; by cbsa; run; data georef.cbsapops03(label='Census 2000 and 2003 Population Estimates for CBSAs' compress=yes); set cbsacopops; by cbsa; 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"; 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 cbsas03.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 June 30, 20&popestyr"; 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"; 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 cbsas03.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 June 30, 20&cbsayr"; footnote4 .h=.7 "Companion Report for Metropolitan Areas is in metropops&popestyr..pdf"; run; ods pdf close; ==========================end comment====================================== */