x cd /pub/data/popests/Tools; %let pgm=aggpopests_uscbsas; filename pgm "&pgm..sas"; /*----------------------------------------------------------------------------------------------------------------- This code aggregates popests county data to create summaries for complete and within-state CBSAs as well as US totals. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Under contract with the Missouri Census Data Center Revision History: 03.24.06 Coding begins. 3/22/2007 8:09AM Update and run for 06 data. 3/13/2008: Update (but do not run yet!) for 07 data. (Running with data 3/20/08) And reran with corrected data for 2007 3-25-08. 3/19/09: Running with latest data thru 2008. Changing name of the output report. 3/23/10: Running with latest data thru 2009. 4/12/12: Runnin with data thru 2011. 3/14/13: Runnin with data thru 2012. 10/10/13: Running with data thru 2012 using 2013 updated cbsa defns. We also added ID variable cbsayr. 3/27/14: Running with data for 2013. 3/26/15: Running with data for 2014. 3/24/16: Running with data for 2015. 3/23/17: Running with data for 2016. ------------------------------------------------------------------------------------------------------*/ options ls=158 ps=80 nodate; %let baseyear=2010; *---it used to be 2000, in an earlier decade... ---*; %let baseyr=%substr(&baseyear,3,2); %let yr=16; *<===========================DO NOT rerun last year!! ===; %let dset=popests.uscomcbsas&yr; libname popests '/pub/data/popests/'; *<========================CHANGE when embargo is lifted!!!!!!!!!!!!!!!===; libname user '/SAS_temp/user'; proc sort data=popests.uscom&yr(keep=cbsa state sumlev cbsatype cbsayr _numeric_ drop=rank: rbirth: rdeath: rnetmig: where=(sumlev='050')) out=aggin; by cbsa state; run; %agg(setin=aggin, setout=aggout, aggby=cbsa state, idvars=cbsatype cbsayr, agglvl=2, grand=yes, means=PctChang PctCh1yr, mweights=Pop&baseyr.C poplastyr, aggvars=_numeric_, debug=0) ; run; proc sort data=aggout; by cbsa _lvl_; run; data _dset(label="US pop ests w components of change &baseyear.-20&yr agg to CBSAs and US tots"); length SumLev $3 Geocode $8 AreaName $96 cbsatype $5 cbsa $5 PartCBSA $1 cbsayr $4 States $16 _states $16; retain _states; drop _states; set aggout; by _lvl_ notsorted cbsa; select (_lvl_); when(1) do; SumLev='311'; geocode=cbsa||'-'||state; areaname=put(cbsa,$cbsa.); if not (first.cbsa and last.cbsa) then do; if CBSA='99999' then areaname='Non-CBSA Portion of '||put(state,$state.); else areaname=trim(tranwrd(areaname,'Statistical Area','SA'))||" - "||put(state,$fipstab2.)||" part"; PartCBSA='y'; if first.cbsa then _states=state; else _states=trim(_states)||' '||state; end; else do; PartCBSA='n'; _states=State; end; end; when(2) do; if cbsa ='99999' then delete; SumLev='310'; geocode=cbsa; areaname=put(cbsa,$cbsa.); States=_states; end; when(99) do; SumLev='010'; geocode=' '; Areaname="U.S. Totals"; cbsatype=' '; end; end; *--select stmt--; format pct: 5.1; drop _lvl_; rename _nag_=ncos; label _nag_='# Counties'; label partcbsa='Part CBSA flag (y/n)' States='State(s) in which CBSA located'; run; *---Modifying code 3-24-08 to get value of states on 311 summaries as well as on the 310s. Except when cbsa is all 9s--; proc sort data= _dset; by cbsa; run; proc sql; create table _states as select cbsa, states from _dset where sumlev='310' and (cbsa ne '99999'); quit; proc print data=_states; id cbsa; run; data &dset; merge _dset(drop=states) _states(in=instates ); by cbsa; if state='29' and sumlev='311' and states=' ' then put / _all_; run; proc contents data=&dset position; run cancel; *--already saw it--; ods pdf file="../Reports/popests&yr._uscbsas.pdf" notoc style=sasweb; proc print label data=&dset; where not (sumlev='311' and partcbsa='n'); *--We delete redundant within-state summaries---; by cbsa areaname notsorted; id cbsa areaname; label cbsa='CBSA code'; title "Population Estimates With Components of Change &baseyear.-20&yr"; title2 "Aggregated from County Data to Metro and Micropolitan Areas (CBSAs) for the United States"; footnote .h=1 "Produced by setup in popests/Tools/&pgm..sas from Data in &dset"; footnote2 .h=1 "CBSAs Definitions Are as of 7-1-2015 (latest available)"; var ncos popest popchang pctChang NetMig NatrlInc; **sum ncos popest popchang; run; ods pdf close;