x cd /pub/data/georef/Tools; %let pgm=states_by_metros; filename pgm "&pgm..sas"; *---Per request from D.L. Robison of UM Extesnsion, asking about states that were comparable to Mo in terms of population located in "2-3 metro centers with the rest of the state being largely rural". We do a report showing each state with its Total popl, that of its 3 largest Metro Areas, its remaining Metros, its micropolitan and its other (rural-ish) areas. For each of these we calculate the pop as a pctage of the state total. ----; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; data statepops; set popests.uscomnst08 ; where ('01' <= state <='56'); cbsatype=' '; keep state popest cbsatype Areaname; run; data cbsaparts; length cbsatype $8; set popests.uscomcbsas08 ; where sumlev='311' and state ne '72'; keep state areaname ncos popest cbsa cbsatype; if cbsatype=' ' then cbsatype='Rural'; run; proc sort; by state cbsatype descending popest; run; data report; length areaname $64; set statepops cbsaparts; by state cbsatype; where state ne '11'; if first.state then do; _StatePop=popest; PctPop=100; CumPct=.; _MicroPop=0; _MicroPct=0; Nmicros=0; Nmetros=0; output; delete; end; if cbsatype='Micro' then do; _Micropop + popest; Nmicros+1; if last.cbsatype then do; Areaname=put(Nmicros,2.)||' Micropolitan Areas'; popest=_micropop; PctPop=100*popest/_StatePop; CumPct+PctPop; output; end; end; else if cbsatype='Metro' then do; NMetros+1; PctPop=100*popest/_statepop; CumPct + PctPop; output; end; else if cbsatype='Rural' then do; PctPop=100*popest/_statePop; CumPct+PctPop; output; end; retain _statepop; keep State AreaName cbsatype cbsa Popest PctPop CumPct; label cbsatype='Geography Type' popest="Latest Pop Estimate (2008)" PctPop='% of State Pop' CumPct='Cumulative %'; label areaname='Area' state='State'; ; format popest comma11. Pct: CumPct 5.1; run; ods pdf file="/pub/reports/geography/&pgm..pdf" style=minimal ; options nodate; proc print data=report label; by state; format state $state.; id cbsatype; var Areaname PopEst PctPop CumPct; title "State Breakdown by Metro Areas, Micropolitan Areas and Other"; footnote "The 'Rural' Category Just Refers to Counties Not Included in Either Kind of CBSA"; footnote2 "Generated by Setup in georef/Tools/states_by_metros"; run; ods pdf close;