x cd /pub/data/popests/Tools; %let pgm=uscomYYnst.cnvt; filename pgm "&pgm..sas"; /*----Setup to read Census Bureau/FSCPE national and state estimates with components of change for estimate year 20YY. Data is for the nation and states only (see uscomYY.cnvt for conversion of county level files). Initial coding, 12/2005 by John Blodgett, Missouri Census Data Center. Idea is to create a reuseable module that will work throughout the decade by just changing the year parm. (But we have yet to see the Bureau provide consecutive years in the same format. ) 12-22-05: Running to run with ests for 7-1-2005. 12-26-2006: Running with ests for 7-1-06 01-02-08: Running with ests for 7-1-07 12-22-08: Running with ests for 7-1-08 12-23-09: Running with ests for 7-1-09 ------*/ %let year=2009; *<=================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/&temp/NST_EST&year._ALLDATA.csv"; *<--as FTPed from Census web site--; *---Above file may be moved to rawdata subdirectory and compressed (.zip file)--; libname popests "/pub/data/popests/&temp"; title "uscomYYnst.cnvt.sas: US Nation and State Pop Estimates with Components of Change"; title2 "For Years 2000 thru &year"; options MPRINT; missing X; *==============Begin Data step==============*; data popests.uscomnst&yr(label="US Nation & State estimates w components of change 2000-&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. Popcen2k length=5 label='Unadjusted Census 2k pop' format=comma9. Pop00C LENGTH= 5 Label="4/1/2000 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/00(c)-7/&yr" format=comma8. PctChang LENGTH=4 Label="% Change in Pop 4/00-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 GQPop LENGTH=4 Label="Group Quarters pop Est. - 7/&yr" format=comma7. Births length=5 Label="Total Births, 4/00 to 7/&yr" format=comma8. Deaths length=5 Label="Total Deaths, 4/00 to 7/&yr" format=comma8. NatrlInc length=4 Label="Natural Increase, 4/00 to 7/&yr" format=comma7. NetMig length=4 Label="Net Migration, 4/00 to 7/&yr" format=comma8. DomMig length=4 Label="Net Domestic Mig 4/00 to 7/&yr" format=comma7. IntMig length=4 Label="Net International Mig 4/00 to 7/&yr" format=comma7. Resdl length=4 label="Residual migration 4/00 to 7/&yr"; %macro attribs; Attrib PopJL00 LENGTH= 5 Label="Total pop (est.) July 00" %do j=1 %to &yr; %let jj=0&j; PopJL&jj LENGTH= 5 Label="Total pop (est.) July &jj" %end; PopCAJ00 LENGTH= 5 Label="Net change in pop: Apr-July 00" %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; PopC&jjm1&jj LENGTH= 5 Label="Net change in pop: 7/&jjm1-7/&jj" %end; BRTHAJ00 LENGTH=5 Label="Births April-July 00 " %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; BRTH&jjm1&jj LENGTH=5 Label="Births 7/&jjm1-7/&jj" %end; DTHAJ00 LENGTH=5 Label="Deaths April-July 00" %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; DTH&jjm1&jj LENGTH=5 Label="Deaths 7/&jjm1-7/&jj" %end; ; Attrib IMIGAJ00 LENGTH=5 Label="Internatnl Migration April-July 00 " %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; IMIG&jjm1&jj LENGTH=5 Label="Internatnl Mig 7/&jjm1-7/&jj" %end; DMIGAJ00 LENGTH=5 Label="Domestic Migration April-July 00" %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; DMIG&jjm1&jj LENGTH=5 Label="Domestic Mig 7/&jjm1-7/&jj" %end; TMIGAJ00 LENGTH=5 Label="Total Net Migration April-July 00 " %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; TMIG&jjm1&jj LENGTH=5 Label="Total Net Migration 7/&jjm1-7/&jj" %end; RSDLAJ00 LENGTH=4 Label="Residual 4/00-7/00" %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; RSDL&jjm1&jj LENGTH=4 Label="Residual 7/&jjm1-7/&jj" %end; %macro gqdum; gqpop2k length=4 Label='Grp Quarters pop, 2K census' gqpopc length=4 Label='Grp Querters pop est base' %do j=0 %to &yr; %let jj=0&j; GQPopJL&jj LENGTH= 4 Label="GQ pop (est.) July &jj" %end; %mend gqdum; ; %mend attribs; %attribs ; %macro intvl(base,nyrs); %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; %if &nyrs=2 %then &base&jjm1&jj ; %else &base&jj ; %end; %mend intvl; infile csvin dsd dlm="," lrecl=4800 firstobs=2 missover; *---we add popca vars to input list starting with vintage 2007 estimates---; input sumlev reg div state areaname popcen2k pop00c popjl00 %intvl(popjl,1) popcaj00 %intvl(popc,2) brthaj00 %intvl(brth,2) dthaj00 %intvl(dth,2) _natinc00 %intvl(_natinc,1) imigaj00 %intvl(imig,2) dmigaj00 %intvl(dmig,2) _netmig00 %intvl(_nemtmig,1) rsdlaj00 %intvl(rsdl,2) ; *----We do NOT read the various rate items at the end of the record added in 2007------------------------; *---Starting with 2008 data release they dropped leading 0s in geocodes so we need to put them back---; 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-pop00c; pctchang=100*popchang/pop00c; poplastyr=popjl&yrm1; popch1yr=popest-poplastyr; pctch1yr=100*popch1yr/poplastyr; if reg='0' then reg=' '; if div='0' then div=' '; popcaj00=popjl00-pop00c; Births=brthaj00; Deaths=dthaj00; IntMig=imigaj00; DomMig=dmigaj00; Resdl=rsdlaj00; tmigaj00=imigaj00 + dmigaj00 + rsdlaj00; ; %macro assigns; %do j=1 %to &yr; %let jj=0&j; %let jm1=%eval(&j-1); %let jjm1=0&jm1; %let sfx=&jjm1&jj; *** popc&sfx=popjl&jj-popjl&jjm1; *--Starting with 2007 data we now read these numbers instead of calculating--; Births + brth&sfx; Deaths + dth&sfx; IntMig + imig&sfx; DomMig+ dmig&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; 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"; *----Generate report for web site in pdf format----; options nodate; ods pdf file='/pub/data/popests/Reports/uscomnst.pdf' title="US State and Nation Estimates With Components of Change, &yearm1.,&year" STYLE=sasweb noTOC; /* =======================Begin comment================ proc rank data=popests.uscomnst&yrm1 (where=(sumlev='040' and state ne '72')) out=ranks&yrm1 descending; var pop00c 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 pop00c 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"; title2 'Part 1: Data Values'; footnote h=1 "Produced by Missouri Census Data Center from setup in uscomYYnst.cnvt.sas run on &sysdate"; proc print data=popests.uscomnst&yr label; id areaname; var pop00c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; format pop00c 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 pop00c 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 pop00c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ); set usranks; run; proc print data=usranks2 label; id areaname; var pop00c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc ; title2 'Part 2: Data Rankings (States Only)'; run; ods pdf close;