x cd /pub/data/popests/Tools; %let pgm=uscom20YY.cnvt; filename pgm "&pgm..sas"; /*----Setup to read Census Bureau/FSCPE estimates with components of change for estimate year 20YY, where YY >= 11 . This is the 2010-2019 decade version of uscomYY.cnvt.sas. Edited for the new decade. Same basic content just different years. Edited all the refs to 2000 and 00 to make them 2010 and 10. That sort of stuff. April 5, 2012: Running the 2011 vintage estimates. Rerunning 10-10-13 to get latest (vintage 2013) CBSA and related codes assinged. March, 2014: running the 2013 data. March, 2015: running the 2014 data. March, 2016: running the 2015 data. March, 2017: running the 2016 data. ------*/ %let year=2016; *<=================EDIT EACH TIME=============; %let yr=%substr(&year,3,2); %let temp=; %*str(temp/); *<===============================set to null after embargo period---; %let cbsacos=cbsacos15; *<====georef dataset containing the latest county-to-cbsa defns--; *--copy (move) this file to popests after embargo--; filename csvin "/pub/data/popests/&temp.CO-EST20&yr.-alldata.csv"; *<--as downloaded from Census web site (embargoed!) --; *---Above file may be moved to rawdata subdirectory and compressed (.zip file)--; libname popests "/pub/data/popests/&temp"; libname georef '/pub/data/georef' access=readonly; filename attribs "uscom&yr..attribs.sas"; *---gets written in last step using %genattr macro---; %let yearm1=%eval(&year-1); %let yrm1=%substr(&yearm1,3,2); %let yrm1_yr=&yrm1&yr; %let yearm2=%eval(&year-2); %let yrm2=%substr(&yearm2,3,2); title "uscom20YY.cnvt.sas: US County Pop Estimates with Components of Change"; title2 "For Years 2010 thru &year"; options MPRINT; /*<=========================Comment out===================================== *==============Begin Data step==============*; data uscom&yr; *--Attribute statement(s) generated by genattr macro, then edited--; Attrib Geoid length=$12 Label='Geographic ID' State LENGTH=$2 Label="FIPS state" Stab length=$2 Label="State Postal Abb" Cnty LENGTH=$3 FIPCO length=$5 County LENGTH=$5 label="FIPS county" AreaName LENGTH=$40 Reg length=$1 label="Region" Div length=$1 label="Division" SumLev LENGTH=$3 Label="Geographic summary level" format=$3. Popcen10 length=5 label='Unadjusted Census 2010 pop' format=comma9. pop10c LENGTH= 5 Label="4/1/2010 resident pop (estimates base) " format=comma9. Popest LENGTH= 5 Label="Latest Total pop Est. - 7/&yr" format=comma9. PopChang LENGTH= 5 Label="Net change in pop 4/10(c)-7/&yr" format=comma8. PctChang LENGTH=4 Label="% Change in Pop 4/10-7/&yr" format=5.1 PopCh1yr length=4 Label="Net change in pop 7/&yrm1-7/&yr" format=comma7. PctCh1yr LENGTH=4 Label="% Change in Pop 7/&yrm1-7/&yr" format=5.1 GQPop LENGTH=4 Label="Group Quarters pop Est. - 7/&yr" format=comma7. Births length=5 Label="Total Births, 4/10 to 7/&yr" format=comma8. Deaths length=5 Label="Total Deaths, 4/10 to 7/&yr" format=comma8. NatrlInc length=4 Label="Natural Increase, 4/10 to 7/&yr" format=comma7. NetMig length=4 Label="Net Migration, 4/10 to 7/&yr" format=comma8. DomMig length=4 Label="Net Domestic Mig 4/10 to 7/&yr" format=comma7. IntMig length=4 Label="Net International Mig 4/10 to 7/&yr" format=comma7. Resdl length=4 label="Residual migration 4/10 to 7/&yr"; %macro attribs; Attrib %do j=10 %to &yr; %let jj=&j; PopJL&jj LENGTH= 5 Label="Total pop (est.) July 20&jj" %end; PopCAJ10 LENGTH= 5 Label="Net change in pop: Apr-July 2010" %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; PopC&jjm1&jj LENGTH= 5 Label="Net change in pop: 7/&jjm1-7/&jj" %end; BRTHAJ10 LENGTH=5 Label="Births April-July 2010 " %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; BRTH&jjm1&jj LENGTH=5 Label="Births 7/&jjm1-7/&jj" %end; DTHAJ10 LENGTH=5 Label="Deaths April-July 2010" %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; DTH&jjm1&jj LENGTH=5 Label="Deaths 7/&jjm1-7/&jj" %end; ; Attrib IMIGAJ10 LENGTH=5 Label="Internatnl Migration April-July 2010 " %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; IMIG&jjm1&jj LENGTH=5 Label="Internatnl Mig 7/&jjm1-7/&jj" %end; DMIGAJ10 LENGTH=5 Label="Domestic Migration April-July 2010" %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; DMIG&jjm1&jj LENGTH=5 Label="Domestic Mig 7/&jjm1-7/&jj" %end; NetMigAJ10 LENGTH=5 Label="Net Migration April-July 2010 " %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; NetMig&jjm1&jj LENGTH=5 Label="Net Migration 7/&jjm1-7/&jj" %end; RSDLAJ10 LENGTH=4 Label="Residual 4/10-7/10" %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; RSDL&jjm1&jj LENGTH=4 Label="Residual 7/&jjm1-7/&jj" %end; gqpopc length=4 Label='Grp Quarters pop est base (2010)' %do j=10 %to &yr; %let jj=&j; GQPopJL&jj LENGTH= 4 Label="GQ pop (est.) July 20&jj" %end; ; format rbirth: rdeath: 7.3; *<--added 3/2017--; %mend attribs; %attribs ; %macro intvl(base,nyrs); %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; %if &nyrs=2 %then &base&jjm1&jj ; %else &base&jj ; %end; %mend intvl; infile csvin dsd dlm="," lrecl=4810 firstobs=2 missover termstr=crlf; length _stname $32; %macro readit; %global year; input sumlev reg div state cnty _stname areaname popcen10 pop10c popjl10 %intvl(popjl,1) popcaj10 %intvl(popc,2) brthaj10 %intvl(brth,2) dthaj10 %intvl(dth,2) _natrinc10 %intvl(_natrinc,2) imigaj10 %intvl(imig,2) dmigaj10 %intvl(dmig,2) netmigaj10 %intvl(netmig,2) rsdlaj10 %intvl(rsdl,2) gqpopc gqpopjl10 %intvl(gqpopjl,1) %intvl(rbirth,2) %intvl(rdeath,2) %intvl(_rnatrinc,2) %intvl(_rimig,2) %intvl(_rdmig,2) %intvl(rnetmig,2) ; %mend readit; %readit *---Make sure these codes have leading zeroes---; sumlev= translate( right(sumlev),'0',' '); state=translate( right(state),'0',' '); cnty=translate( right(cnty),'0',' '); if sumlev='050' then fipco=state||cnty; if state ne '00' then stab=put(state,$fipstab.); popest=popjl&yr; popchang=popest-pop10c; pctchang=100*popchang/pop10c; poplastyr=popjl&yrm1; popch1yr=popest-poplastyr; pctch1yr=100*popch1yr/poplastyr; gqpop=gqpopjl&yr; if reg='0' then reg=' '; if div='0' then div=' '; if cnty='000' then cnty=' '; *<---wish they would be consistent---; if cnty ne ' ' then county=state||cnty; popcaj10=popjl10-pop10c; Births=brthaj10; Deaths=dthaj10; IntMig=imigaj10; DomMig=dmigaj10; Resdl=rsdlaj10; NetMig= netmigaj10; %macro assigns; %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let jjm1=&jm1; %let sfx=&jjm1&jj; ***popc&sfx=popjl&jj-popjl&jjm1; Births + brth&sfx; Deaths + dth&sfx; IntMig + imig&sfx; DomMig+ dmig&sfx; Resdl+ rsdl&sfx; NetMig + netmig&sfx; %end; %mend assigns; %assigns ; NatrlInc=Births - Deaths; **NetMig= Popchang - NatrlInc; *<---We now just sum the net values read in----; retain geoid "sss00USggggg"; substr(geoid,1,3)=Sumlev; if sumlev='050' then substr(geoid,8,5)=county; else if sumlev='040' then substr(geoid,8)=state; if sumlev='040' and state='29' then put / _all_; *<---for verifying data---------------------------------; format rbirth: rdeath: rnetmig: 6.2; drop _: ; run; *--we get the metro area (CBSA) codes, from the georef.cbsacos dataset.---; *=========We originally ran this when the cbsacos dataset was vintage 2009. But now (10/13) we rerun when it has been upodated with vintage 2013 codes published in 2/13. We will also have to run the aggpopests_uscbsas run after this.-; *--for the 2015 data cylcle we use the vintage 7/15 cbsa codes.---*; data metrocodes; set georef.&cbsacos(keep=State CBSA CSA MetroDiv county cbsaname cbsatype Central year rename=(Year=cbsayr)); ***where sumlev in ('050') and geocomp='00' and state le '56'; *--added CSA and Central for 2016 estimates run--; where state ne '72'; *----2 county codes changed in 2016 and are not reflected in the cbsacos15 data set (and later?). So we patch it here--; ******<====; if county='02270' then county='02158'; *--Wade Hampton AK became Kusilvak --; if county='46113' then county='46102'; *--Shannon, SD became Oglal Lakota --*; run; proc sort data=metrocodes; by state county; run; *<---because we edited some county codes in previous step--; data popests.uscom&yr(sortedby=state county label="U.S. State and county components of Pop Chng 2010-&year" ) ; merge metrocodes(in=ingeos) uscom&yr(in=thisyr); *** archives.uscom04(keep=state county gqpop2k); by state county; if sumlev ne '040' and not (thisyr and ingeos) then do; put '***Non match of this county: ' thisyr= ingeos= county= county $5.; if thisyr; end; if cbsa=' ' and sumlev='050' then cbsa='99999'; run; options nosymbolgen; *--create pair of views to be used as input to proc rank---*; *--ALSO, create the views for the state of Missouri--; proc sql; create view work.rankin as select SumLev, state, county, popest, pop10c, popchang, popch1yr, pctchang, pctch1yr, netmig, natrlinc from popests.uscom&yr where SumLev in ('040','050') order by SumLev; quit; *--rank the data, by counties and by states--; proc rank data=work.rankin descending out=ranks; by SumLev; ranks rankpop rankp10c rankchng rankpctc rankch1y rankpct1 ranknetm ranknati; var popest pop10c popchang pctchang popch1yr pctch1yr netmig natrlinc; run; proc sort data=ranks; by state sumlev county; run; *<--prepare to run update step to add ranks--; proc print data=ranks(drop=county); title3 'State Rankings '; where SumLev='040'; by SumLev; id state; format state $fipstab.; run; data popests.uscom&yr; update popests.uscom&yr ranks; by state county; Attrib RankPop length=4 label="Rank: Total Pop (Est) &year" format=4. RankP10c length=4 label="Rank: Total Pop est base 4-1-10" format=4. RankChng LENGTH=4 label="Rank: Pop Change 2010-&year" format=4. RankPctc length=4 label="Rank: % Change 2010-&year" format=4. RankCh1y length=4 label="Rank: Pop Change &yearm1-&year" format=4. RankPct1 length=4 label="Rank: % Change &yearm1-&year" format=4. RankNetm length=4 label="Rank: Net Migration, 2010-&year" format=4. RankNatI length=4 label="Rank: Natural Increase, 2010-&year" format=4.; if sumlev not in ('040','050') then _error_=0; run; *---create state and cbsa indices of the uscom&yr data set--; proc datasets library=popests nolist; modify uscom&yr; index create state; index create cbsa; quit; proc freq data=popests.uscom&yr(keep=sumlev state cbsa cbsatype cbsayr); title3 "Frequencies on Selected Variables from popests.uscom&yr"; tables sumlev state cbsayr / missing; ***table state*cbsa*cbsatype /list missing; format cbsa $cbsa.; run; proc contents data=popests.uscom&yr ; title3 "SAS Contents Report for popests.uscom&yr"; run; *---create the new and improved popests.mocom&yr dataset (not a view)----; *---We will replace the national rankings for the counties with state rankings in the mo subset (new, 3-31-09, per tck urging-----; proc sql; create view work.rankinmo as select SumLev, state, county, popest, pop10c, popchang, popch1yr, pctchang, pctch1yr, netmig, natrlinc from popests.uscom&yr where SumLev ='050' and state='29'; quit; proc rank data=work.rankinmo descending out=ranksmo; ranks rankpop rankp10c rankchng rankpctc rankch1y rankpct1 ranknetm ranknati; var popest pop10c popchang pctchang popch1yr pctch1yr netmig natrlinc; run; data popests.mocom&yr(label="Mo estimates with components of change thru 20&yr"); length SumLev $3 county fipco $5 ; merge popests.uscom&yr(in=inests where=(state='29') ) ranksmo(in=inranks) georef.mocogeos(in=ingeos drop=cbsa: ) ; by county; if not ingeos and inranks and sumlev='050' then do; put //"****error in merge step creating mocom&yr dataset **** " / _all_; abort abend; end; if sumlev='040' then do; fipco='29000'; county=fipco; end; run; proc transpose data=popests.mocom&yr out=popests.mocom&yr.t(label="Transposed version of mocom&yr") name=variable label=Item_Description prefix=c; id fipco; idlabel areaname; label variable='Variable' item_description='Item Description'; run; proc print data=popests.mocom&yr.t; title2 "popests.mocom&yr.t"; run; %genattr(setin=popests.uscom&yr,fileout=attribs) ; ===========================End commented out================================ */ *--This would generate a skeleton SAS coding file that we can edit and incorporate into the conversion code on subsequent run--; options pagesize=240 ls=155 ; title3 "Selected Variables from popests.mocom&yr"; proc print data=popests.mocom&yr label; by state; format state $state.; id county; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc rankpop rankchng rankpctc rankch1y rankpct1; run; *---generate a report for Reports library----; ods pdf file="../Reports/popests_mocounties&yr..pdf" title='Missouri Census Data Center Estimates Report' bookmarkgen=no style=sasweb; ods listing close; options nodate; proc print label data=popests.mocom&yr; title "Population Estimates With Components of Change 2010-20&yr"; title2 height=1 "Missouri and Its Counties"; footnote .h=1 "Produced by setup in popests/Tools/&pgm..sas from data in popests.mocom&yr"; ***footnote2 .h=1 "Ranks for counties are based on 3141 U.S. counties and county equivalents"; id county; var popest popchang pctChang NetMig NatrlInc rankp10c rankpop rankchng rankpctc ; run; ods pdf close;