x cd /pub/data/georef/Tools; %let pgm=cbsas20; 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 September, 2018. See https://www.census.gov/geographies/reference-files/time-series/demo/metro-micro/delineation-files.html for original source of these data. Update https://mcdc.missouri.edu/reports/geography/index.html to update references to the latest reports as generated here. */ %include '/pub/sas/autoexec.sas'; %let setsfx = 20; *<== 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 = 2020; %let month = Mar; %let popestyr = 19; *<== we get population estimates from popests.uscom&popestyr ; %let pyr = %eval(&popestyr - 1); filename in "../cbsas&cbsayr..csv"; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; libname user '/home/riceg/work'; 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. ; *-- We already had data sets with these names from last cycle so did not need to run in 8/2015 ; proc datasets library=georef nolist; *change metrodivs=metrodivs17; *change csacbsas=csacbsas16; *change cbsas=cbsas16; change cbsacos=cbsacos18; *change cbsapops=cbsapops16; quit; *NOTE: Changing the name GEOREF.CBSACOS to GEOREF.CBSACOS16 (memtype=DATA). ; *NOTE: Changing the name GEOREF.CBSAPOPS to GEOREF.CBSAPOPS16 (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 csa Year state) metrodivs(keep=cbsa cbsaname MetroDiv AreaName Year state) csacbsas(keep=state cbsa cbsaname csa csaname Year) cbsacos(keep=stab state cnty county fipco cbsa cbsatype cbsaname metrodiv csa Central Year); infile in end=last dsd truncover firstobs=4 ; length CBSA $5 MetroDiv $5 county $5 AreaName $80 cbsaname $5 csa $3 csaname $80 Central $8; length fipco cbsatype $5 State Stab $2 cnty $3; retain Year "&cbsayr"; input cbsa $5. @; if length(cbsa)=5 and verify(cbsa,'0123456789')=0; *---look for lines with 5-digit numerics in cols 1-5--; length _cbsatitle _metdivtitle _csatitle $80 _cntyname $40 ; input @7 MetroDiv csa _cbsatitle cbsatype _metdivtitle _csatitle _cntyname _statename $ State cnty Central ; stab=put(state,$fipstab2.); County=state||cnty; format county $county.; fipco=county; format fipco $5.; cbsaname=cbsa; **if cbsa='14260' then put / _all_; *****diagnostic to see what happened to metrodiv counties***; format cbsaname $cbsa.; *<---associate a format code with this so it prints the name.--; if cbsa='41180' and county='29055' then delete; *<----we omit the Crawford county entry for the St Louis metro area. Bogus--; *---output to (up to depending) 4 data sets---; output cbsacos; AreaName=_cbsatitle; csaname=_csatitle; output cbsas; AreaName=_metdivtitle; if metrodiv ne ' ' then output metrodivs; if csa ne ' ' then output csacbsas; run; proc sort data=metrodivs out=georef.metrodivs&setsfx(index=(metrodiv) label="Metropolitan Divisions as of &month, &cbsayr") nodupkeys; by cbsa metrodiv; run; *---(USED TO .,, ) 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 CANCEL; *--INSTEAD ... we now run the following step to get csacbsas&setsfx--; proc sort data=csacbsas nodupkeys out=georef.csacbsas&setsfx; by csa cbsa state; run; proc datasets nolist library=georef; modify csacbsas&setsfx; index create csa; index create cbsa; quit; proc sort data=cbsas; by cbsa state; run; data georef.cbsas&setsfx(index=(cbsa) label="Core Based Stat Areas &month, &cbsayr"); set cbsas(in=incbsas); length States $20 nstates 3; retain States; by cbsa state; if first.cbsa then do; states=' '; _ix=0; nstates=0; end; if first.state then do; nstates+1; _ix=1+ (nstates-1)*3; substr(states,_ix)=state; end; if last.cbsa then do; length csaname $80; csaname=put(csa,$csa.); states=left(states); output; end; drop _: state; run; /* libname fmts "/pub/sas/catalogs"; *----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,library=fmts); %genfmat(setin=georef.metrodivs&setsfx,argvars=metrodiv,arglen=5,labelvar=areaname,labellen=80,fmatname=metrodiv, textfile=text2,savedoc=1,library=fmts); 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,library=fmts); run; libname fmts clear; */ *---Merge population from our popests dataset, July, 20&popestyr vintage, with the county level set. We keep a complete set of post-2010 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 Popcen10 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; *----adding code 6-12-17 to copy this latest cbsacos&setsfx to cbsacos. Earlier we tried using a soft link to make cbsacos an alias for cbsacos15 but we had trouble because set had an index and we got error msgs saying set was damaged. ----; data georef.cbsacos; set georef.cbsacos&setsfx; run; proc datasets nolist library=georef; modify cbsacos; 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; *---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 popcen10 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 Popcen10 PopJL&popestyr; sum PopCen10 PopJL&popestyr ; label Popcen10='Census 2010 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 popcen10 popjl&popestyr county) out=cbsacopops; by cbsa; run; data georef.cbsapops(label='Census 2010 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.); _Pop10=Popcen10; _popest=Popjl&popestyr; end; else do; counties=trim(counties)||', '||put(county,$county.); _pop10 + popcen10; _popest + Popjl&popestyr; end; if last.cbsa then do; popcen10=_pop10; Popjl&popestyr=_popest; output; end; format popcen10 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: 2010 Census and July, 20&popestyr Estimate"; proc print data=georef.cbsapops(where=(cbsatype='Metro')) label uniform; id cbsaname; var cbsa counties popcen10 popjl&popestyr; label cbsaname='Metropolitan Area' cbsa='CBSA Code' popcen10='2010' popjl&popestyr="20&popestyr"; format popcen10 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: 2010 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 popcen10 popjl&popestyr; label cbsaname='Micropolitan Area' cbsa='CBSA Code' popcen10='2010' popjl&popestyr="20&popestyr"; format popcen10 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; */