x cd /pub/data/popests/Tools; %let pgm=uscomYY.cnvt; filename pgm "&pgm..sas"; /* see uscom20YY.cnvt for current version of this setup */ /*----Setup to read Census Bureau/FSCPE estimates with components of change for estimate year 20YY. Data is for the nation, states and counties. Initial coding, 4/2003 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. ) June, 2003: Adding aggregation step to calculate state totals, now that the Bureau has stopped including them on the input file. April, 2004: Changed their minds again. Now they give us not only US but also region and div totals. So now we have to remove the whole agg step and add code to recognize the new sum levels. Bummer. April, 2005: Attempting to run with ests for 7-1-2004. March, 2006: Attempting to run with ests for 7-1-2005. They dropped gqpop2k and leading 0s from code fields. May, 2006: Running again to fix label on variables rankch1y and rankpct1 . Aug, 2006: Rerun with merging of data from uscom04 to get the 2000 census gqpop2k and gqpopc figures. March, 2007: Running with 2006 estimates. We now are reading gqpopc but still have to merge gqpop2k from archives dataset. March 2008: After problem conversion on 3-20 we fixed input to reflect more changes in 07 version and reconverted on 3-25-08. March 2009: Running with 2008 estimates. May 2009: Rerunning the 2008 data to add geoid. March 2010: Running the 2009 estimates. (Comment added 6-1-11, but is it true? No .log or .lst files found for the 3/10 date). ------*/ %let year=2008 ; *<=================EDIT EACH TIME=============; %let yr=%substr(&year,3,2); %let temp=; *<-------------set to null to write output directly to popests data directory---; ***filename csvin "/pub/data/popests/&temp/uscom&yr..csv"; *<--as FTPed from Census web site--; filename csvin "/pub/data/popests/temp/CO-EST20&yr.-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"; %*libname(sf12000); libname georef '/pub/data/georef' access=readonly; libname archives "/pub/data/popests/archives" 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 "uscomYY.cnvt.sas: US County Pop Estimates with Components of Change"; title2 "For Years 2000 thru &year"; options MPRINT; *==============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. 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 attr(vn,vlab,time,y1,y2,m1=jul,m2=jul,len=5 ); %*---NOT used!!!--; %if y1=AJ %then %let time1=April; %else %let time1=&time; %if %quote(&y2)=%str() %then %let time2=&time &y1; %else %let time2=&time1 &y1 %str( to ) &time &y2; %*--here is the generated attrib code for the variable----; &vn.&y1&y2 LENGTH=&len Label="&vlab &time2" %mend attr; %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; 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 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; *---gqpopjl is back for 2004 data---; infile csvin dsd dlm="," lrecl=4800 firstobs=2 missover; length _stname $32; %macro readit; %global year; %if &year=2006 %then %do; input sumlev state cnty reg div areaname _stname popcen2k pop00c popjl00 %intvl(popjl,1) brthaj00 %intvl(brth,2) dthaj00 %intvl(dth,2) imigaj00 %intvl(imig,2) dmigaj00 %intvl(dmig,2) rsdlaj00 %intvl(rsdl,2) gqpopc gqpopjl00 %intvl(gqpopjl,1) ; %end; %else %if &year ge 2007 %then %do; input sumlev reg div state cnty _stname areaname popcen2k pop00c popjl00 %intvl(popjl,1) popchang00 %intvl(popchang,2) brthaj00 %intvl(brth,2) dthaj00 %intvl(dth,2) _natrinc00 %intvl(_natrinc,2) imigaj00 %intvl(imig,2) dmigaj00 %intvl(dmig,2) _tmigaj00 %intvl(_tmig,2) rsdlaj00 %intvl(rsdl,2) gqpopc gqpopjl00 %intvl(gqpopjl,1) ; %end; %mend readit; %readit *---Starting with the 2005 data the Bureau left off the leading 0s on the geocodes so we have to put them back--; 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-pop00c; pctchang=100*popchang/pop00c; 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; 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; *** O65c&sfx=o65pjl&jj-o65pjl&jjm1; *** U65c&sfx=u65pjl&jj-u65pjl&jjm1; 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--; if sumlev='040' and state='29' then put / _all_; *<---for verifying data---------------------------------; 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; drop _: ; run; *--we get the metro area codes , including both the old 2000 MSACMSA and PMSA codes as well as the most recent CBSA codes, from the georef.cbsacos dataset.---; data metrocodes; set georef.cbsacos(keep=State CBSA MetroDiv county cbsaname cbsatype year MSACMSA PMSA NECMA rename=(Year=cbsayr)); ***where sumlev in ('050') and geocomp='00' and state le '56'; where state ne '72'; run; data popests.uscom&yr(sortedby=state county label="U.S. State and county components of Pop Chng 2000-&year" ) ; *<=========================edited 8-28-06 to add the archives dataset to the merge=====================; merge metrocodes(in=ingeos) uscom&yr(in=thisyr) archives.uscom04(keep=state county gqpop2k); by state county; if sumlev='050' and not (thisyr and ingeos) then do; put '***Non match of this county: ' thisyr= ingeos= county= county $county.; if thisyr; end; if sumlev='050' then do; if div='1' then do; msacmsa=necma; pmsa='####'; end; else necma='####'; if cbsa=' ' then cbsa='99999'; end; label msacmsa='MSA/CMSA/NECMA 2000'; 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 popests.mocom&yr as select * from uscom&yr where state='29'; *----See below where we now create this sas file as a regular dataset after merging with mocogeos---; create view work.rankin as select SumLev, state, county, popest, pop00c, 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 rankp00 rankchng rankpctc rankch1y rankpct1 ranknetm ranknati; var popest pop00c 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. RankP00 length=4 label="Rank: Total Pop est base 4-1-00" format=4. RankChng LENGTH=4 label="Rank: Pop Change 2000-&year" format=4. RankPctc length=4 label="Rank: % Change 2000-&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, 2000-&year" format=4. RankNatI length=4 label="Rank: Natural Increase, 2000-&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, pop00c, 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 rankp00 rankchng rankpctc rankch1y rankpct1 ranknetm ranknati; var popest pop00c 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') drop=necma pmsa ) 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(drop=popchang0:) 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) ; *--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 pop00c popest popchang pctchang PopCh1yr PctCh1yr NetMig DomMig NatrlInc rankpop rankchng rankpctc rankch1y rankpct1; run; *---generate a report for Reports library----; ods pdf file="../&temp/Reports/popests_mocounties.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 2000-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 rankp00 rankpop rankchng rankpctc ; run; ods pdf close; options mprint nosymbolgen;