x cd /pub/data/popests/Tools; %let pgm=uscom201Ynst.cnvt; filename pgm "&pgm..sas"; /*----Setup to read Census Bureau/FSCPE national and state estimates with components of change for estimate year 201Y. Data is for the nation and states only (see uscomYY.cnvt for conversion of county level files). Adapted from uscomYYnst.cnvt which worked with these files in the previous decade (2000-2009) ***Starting with this decase the Bureau has a net migration field on the file which we shall now read and save as netmig variables, replacing the old tmig (total net mig) that we had calculated and saved in earlier years. 12-22-15: Running with estimates for 7-1-15 (moving to post-2010) 06-12-17: running with 2016 vintage ests. ------*/ %let year=2016; *<=================EDIT EACH TIME=============; %let yr=%substr(&year,3,2); %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); %let temp=; *<-------------set to null to write output directly to popests data directory---; **filename csvin "/pub/data/popests/rawdata/NST-EST&year.-alldata.csv"; filename csvin "/pub/data/popests/rawdata/nst-est&year.-alldata.csv"; *--filename using lower case w 2016 data--; *<--as FTPed from Census web site: https://www2.census.gov/programs-surveys/popest/datasets/2010-2016/national/totals/; *---Above file may be moved to rawdata subdirectory and compressed (.zip file)--; libname popests "/pub/data/popests/&temp"; title "uscom201Ynst.cnvt.sas: US Nation and State Pop Estimates with Components of Change"; title2 "For Years 2010 thru &year"; options MPRINT; missing X; /*<=========================Comment out===================================== *==============Begin Data step==============*; data popests.uscomnst&yr(label="US Nation & State estimates w components of change 2010-&year"); *--Attribute statement(s) generated by genattr macro, then edited--; Attrib State LENGTH=$2 Label="FIPS state" Stab length=$2 Label="State Postal Abb" 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 20100 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=f5.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=f5.1 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=5 Label="Natural Increase, 4/10 to 7/&yr" format=comma7. NetMig length=5 Label="Net Migration, 4/10 to 7/&yr" format=comma8. DomMig length=5 Label="Net Domestic Mig 4/10 to 7/&yr" format=comma7. IntMig length=5 Label="Net International Mig 4/10 to 7/&yr" format=comma7. Resdl length=4 label="Residual migration 4/10 to 7/&yr"; *** GQPop LENGTH=4 Label="Group Quarters pop Est. - 7/&yr" format=comma7.; *--once upon a time... --; %macro attribs; Attrib PopJL10 LENGTH= 5 Label="Total pop (est.) July 2010" %do j=11 %to &yr; %let jj=&j; PopJL&jj LENGTH= 5 Label="Total pop (est.) July &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); PopC&jm1&jj LENGTH= 5 Label="Net change in pop: 7/&jm1-7/&jj" %end; BRTHAJ10 LENGTH=5 Label="Births April-July 2010 " %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); BRTH&jm1&jj LENGTH=5 Label="Births 7/&jm1-7/&jj" %end; DTHAJ10 LENGTH=5 Label="Deaths April-July 2010" %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); DTH&jm1&jj LENGTH=5 Label="Deaths 7/&jm1-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); IMIG&jm1&jj LENGTH=5 Label="Internatnl Mig 7/&jm1-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); DMIG&jm1&jj LENGTH=5 Label="Domestic Mig 7/&jm1-7/&jj" %end; NmigAJ10 LENGTH=5 Label="Net Migration April-July 2010 " %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); Nmig&jm1&jj LENGTH=5 Label="Net Migration 7/&jm1-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); RSDL&jm1&jj LENGTH=4 Label="Residual 7/&jm1-7/&jj" %end; %macro gqdum; %*---They used to provide this estimate but quit doing so some years ago--; gqpop10 length=4 Label='Grp Quarters pop, 2010 census' gqpopc length=4 Label='Grp Quarters pop est base' %do j=10 %to &yr; GQPopJL&jj LENGTH= 4 Label="GQ pop (est.) July 20&jj" %end; %mend gqdum; ; %mend attribs; %attribs ; %macro intvl(base,nyrs); %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %if &nyrs=2 %then &base&jm1&jj ; %else &base&jj ; %end; %mend intvl; infile csvin dsd dlm="," lrecl=2400 firstobs=2 missover; input sumlev reg div state areaname popcen10 pop10c popjl10 %intvl(popjl,1) popcaj10 %intvl(popc,2) brthaj10 %intvl(brth,2) dthaj10 %intvl(dth,2) _natinc10 %intvl(_natinc,1) imigaj10 %intvl(imig,2) dmigaj10 %intvl(dmig,2) nmigaj10 %intvl(nmig,2) rsdlaj10 %intvl(rsdl,2) ; *----We do NOT read the various rate items at the end of the record ------------------------; *---Starting with 2008 data release they dropped leading 0s in geocodes so we need to put them back---; *--(as of 2015 the leading 0s are back on the file but we keep this recode just in case--; if length(sumlev)=2 then sumlev='0'||sumlev; if sumlev='010' then state='00'; else if sumlev ne '040' then state=' '; else if length(state)=1 then state='0'||state; if sumlev='040' 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; if reg='0' then reg=' '; if div='0' then div=' '; popcaj10=popjl10-pop10c; Births=brthaj10; Deaths=dthaj10; IntMig=imigaj10; DomMig=dmigaj10; Resdl=rsdlaj10; Netmig=nmigaj10; **** tmigaj10=imigaj10 + dmigaj10 + rsdlaj10; ; %macro assigns; %do j=11 %to &yr; %let jj=&j; %let jm1=%eval(&j-1); %let sfx=&jm1&jj; *** popc&sfx=popjl&jj-popjl&jm1; *--Starting with 2007 data we now read these numbers instead of calculating--; Births + brth&sfx; Deaths + dth&sfx; IntMig + imig&sfx; DomMig+ dmig&sfx; NetMig + nmig&sfx; Resdl+ rsdl&sfx; *--aggregate the components of migration: international, domestic and (no longer reported) federal citizen movement to create total mig. --; tmig&sfx = imig&sfx + dmig&sfx + rsdl&sfx; %end; %mend assigns; %assigns ; NatrlInc=Births - Deaths; *** NetMig= Popchang - NatrlInc; *<---also its the sum of the 3 mig items: intmig, dommig and resdl--; drop _: ; run; *---Test step to see if we can pin down how the migration items add up---; data _null_; set popests.uscomnst&yr (where=(state='29')); _popchangeCalc=netmig + natrlinc; if popchang ne _popchangeCalc then put / _all_; run; options nosymbolgen; *--create pair of views to be used as input to proc rank---*; *--ALSO, create the views for the state of Missouri--; ods exclude Contents.DataSet.Variables; proc contents data=popests.uscomnst&yr position; title3 "SAS Contents Report for popests.uscomnst&yr"; run; options pagesize=60 ls=155 ; title3 "Selected Variables from popests.uscomnst&yr"; ===========================End commented out================================ */ *----Generate report for web site in pdf format----; options nodate pagesize=25; ods listing close; *--we added this stmt and added a yr suffix to the pdf filename 6-17---; ods pdf file="/pub/data/popests/Reports/uscomnst&yr..pdf" title="US State and Nation Estimates With Components of Change, &yearm1.,&year" STYLE=meadow noTOC; /* =======================Begin comment================ proc rank data=popests.uscomnst&yrm1 (where=(sumlev='040' and state ne '72')) out=ranks&yrm1 descending; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; run; proc rank data=popests.uscomnst&yr (where=(sumlev='040' and state ne '72')) out=ranks&yr descending; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; run; data popests.uscomnst&yr.reptdata; set popests.uscomnst&yrm1(in=in1d where=(sumlev in ('010','040')) popests.uscomnst&yr (in=in2d where=(sumlev in ('010','040')) ranks&yrm1 (in=in1r) ranks&yr (in=in2r); by state; length DataItem $32; if in1d then DataItem="Value last year (&yearm1)"; else if in2d then DataItem="Value this year (&yearm)"; else if in1r then DataItem="Rank last year"; else if in2r then DataItem="Rank this year"; .................to be continued............. Do a report that focuses on trends comparing this year with last year.... ======================End comment================== */ title "US State and Nation Pop Estimates 7-1-&YEAR With Components of Change Since 2010"; title2 'Part 1: Data Values'; footnote h=.5 "Produced by Missouri Census Data Center from setup in uscom201Ynst.cnvt.sas run on &sysdate"; proc print data=popests.uscomnst&yr label; id areaname; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; format pop10c popest comma11. popchang comma10. netmig dommig natrlinc comma9.; run; proc rank data=popests.uscomnst&yr (where=(sumlev='040' and state ne '72')) out=usranks descending; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; run; data usranks2; *--Use this to put labels back to original values--; if 0 then set popests.uscomnst&yr(keep= areaname pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ); set usranks; run; proc print data=usranks2 label; id areaname; var pop10c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; title2 'Part 2: Data Rankings (States Only)'; run; ods pdf close;