x cd /pub/data/popests/Tools; %let pgm=poptrendcomps; filename pgm "&pgm..sas"; *---3/13, jgb. Create the popests.poptrendcomps data set to be used in the poptrendscomp web app and other places. We combine and restructure (with time as part of the row dimension instead of going across) various uscom data sets. Initially created with data going from 1990 to 2012 in March, 2013. Plan is to add a new set of data each year as they are released. ---*; %let lastyear=2012; *<==================change each year===============================; %let lastyr=%substr(&lastyear,3,2); %let lastyrm1=%eval(&lastyr - 1); %libname(popests,opts=); libname user '/SAS_temp/user'; %let keepids=SumLev State County esriid AreaName; %let keepdata=popjl: popc: brth: dth: netmig: dmig: imig: gqpopjl: ; /* ========================begin comment==================================== *---Phase I: Do pre-merge standardizations so we have consistent ID variables for the 3 decades (data sets) and the special decade-of-the-20xxs data set. ---; *------The data for the 1990-99 decade--------------; data uscom99b; set popests.uscom99(rename=( slvl=SumLev tmig9091=NetMig9091 tmig9192=NetMig9192 tmig9293=NetMig9293 tmig9394=NetMig9394 tmig9495=NetMig9495 tmig9596=NetMig9596 tmig9697=NetMig9697 tmig9798=NetMig9798 tmig9899=NetMig9899)); length esriid $5; if sumlev='040' then do; county=state; esriid=state; end; else esriid=county; *---GQ pop on this data set has beginning and end values but only delta values for interveaning years. We have to restructure it for consistency with the other two decades.---; length gqpopjl91-gqpopjl98 4; array gqpop(*) gqpopjl91-gqpopjl99; _savegqpop99=gqpjl99; *--we can recalculate it in loop and check results--; array gqpopc(*) gqpc9091 gqpc9192 gqpc9293 gqpc9394 gqpc9495 gqpc9596 gqpc9697 gqpc9798 gqpc9899; length gqpopjl90 gqpopjl99 4; gqpopjl90=gqpjl90; gqpopjl99=gqpjl99; _gqpopsum=gqpopjl90; do i=1 to 9; _gqpopsum + gqpopc{i}; gqpop{i}=_gqpopsum; end; if gqpop{9} ne _savegqpop99 then do; put "***We have an error: gqpop sum does not match reported value for July 1999" sumlev= county= areaname= gqpopjl99= _savegqpop99=; _nbad+1; if _nbad gt 25 then abort abend; end; keep &keepids &keepdata; run; *---Create US totals---; proc summary data=uscom99b(where=(sumlev='040')) sum noprint ; class state; var _numeric_; output out=uscom99a sum= ; run; data uscom99; if 0 then set uscom99b; *--to get these variables first---; set uscom99a (in=ustots obs=1) uscom99b; if ustots then do; SumLev='010'; State='00'; Areaname='United States'; esriid=' '; end; drop _: ; run; *-------The data for the 2000-2009 decade---------------*; data uscom09b; set popests.uscom09(rename=( tmig0001=NetMig0001 tmig0102=NetMig0102 tmig0203=NetMig0203 tmig0304=NetMig0304 tmig0405=NetMig0405 tmig0506=NetMig0506 tmig0607=NetMig0607 tmig0708=NetMig0708 tmig0809=NetMig0809)); length esriid $5; if sumlev='040' then esriid=state; else esriid=county; if sumlev='040' then county=state; keep &keepids &keepdata; run; *---Create US totals---; proc summary data=uscom09b(where=(sumlev='040')) sum noprint ; class state; var _numeric_; output out=uscom09a sum= ; run; data uscom09; if 0 then set uscom09b; *--to get these variables first---; set uscom09a (in=ustots obs=1) uscom09b; if ustots then do; SumLev='010'; State='00'; Areaname='United States'; esriid=' '; end; drop _: ; run; *-------The data for the 2010-201X decade (changes each year) --------------*; data uscom&lastyr.b; set popests.uscom&lastyr; length esriid $5; if sumlev='040' then esriid=state; else esriid=county; if sumlev='040' then county=state; keep &keepids &keepdata; run; *---Create US totals---; proc summary data=uscom&lastyr.b(where=(sumlev='040')) sum noprint ; class state; var _numeric_; output out=uscom&lastyr.a sum= ; run; data uscom&lastyr; if 0 then set uscom&lastyr.b; *--to get these variables first---; set uscom&lastyr.a (in=ustots obs=1) uscom&lastyr.b; if ustots then do; SumLev='010'; State='00'; Areaname='United States'; esriid=' '; end; drop _: ; run; data _null_; merge uscom09(in=in09 keep=_character_) uscom12(in=in12 keep=_character_); by county; if not (in09 and in12) or not first.county; put /_all_; _n+1; if _n ge 22 then stop; run cancel; *---this step showed 3 county equivs in Alaska not matched in uscom12---; ==========================end comment====================================== */ *-------The data for the census decade 2000, 2010 (what to do??)--------------*; data uscom00_10b; set popests.uscom00_10; length esriid $5; if sumlev='040' then esriid=state; else esriid=county; if sumlev='040' then county=state; keep &keepids pop00c pop10c brthaj10 dthaj10 births deaths natinc popchang netmigEst ; rename deaths=dths00_10 births=births00_10 natinc=natinc00_10 popchang=popc00_10 netmigest=NetMig00_10; run; *---Create US totals---; proc summary data=uscom00_10b(where=(sumlev='040')) sum noprint ; class state; var _numeric_; output out=uscom00_10a sum= ; run; data uscom00_10; if 0 then set uscom00_10b; *--to get these variables first---; set uscom00_10a (in=ustots obs=1) uscom00_10b; if ustots then do; SumLev='010'; State='00'; Areaname='United States'; esriid=' '; end; drop _: ; run; *---------------Phase 2: Create the input data set, trends. -----------------------------; data trends; merge uscom99 (in=in90s ) uscom09(in=in00s) uscom&lastyr (in=inlatest) uscom00_10(in=indecade); by county; ****where sumlev='040' or state='29'; format sumlev $3.; array _popend(*) popjl90-popjl99 popjl00 - popjl09 popjl10-popjl&lastyr; array _brths (*) brth9091 -- brth9899 brth9900 brth0001 -- brth0809 brth0910 brth1011 - brth&lastyrm1&lastyr; array _dths (*) dth9091 -- dth9899 dth9900 dth0001 -- dth0809 dth0910 dth1011 - dth&lastyrm1&lastyr; array _popcs (*) popc9091 -- popc9899 popc9900 popc0001 -- popc0809 popc0900 popc1011 - popc&lastyrm1&lastyr; *--Note that we changed variables names in the post-2010 sets. tmig becomes netmig. --; array _netmig (*) NetMig9091 -- NetMig9899 NetMig9900 NetMig0001 -- NetMig0809 neNetMig0910 neNetMig1011 - neNetMig&lastyrm1&lastyr; array _dmig (*) dmig9091 -- dmig9899 dmig9900 dmig0001 -- dmig0809 dmig0910 dmig1011 - dmig&lastyrm1&lastyr; array _imig (*) imig9091 -- imig9899 imig9900 imig0001 -- imig0809 imig0910 imig1011 - imig&lastyrm1&lastyr; length Perno 3 Period $12 default=5; attrib Year length=$4 label='Year (Start of Interval)'; fipco=county; format county $county16.; PerNo=0; do _year=1990 to %eval(&lastyear-1); PerNo+1; Year=put(_year,4.); _yearp1=_year+1; Period=Year||'-'|| put(_yearp1,4.); if year='1999' then do; end; else if year='2009' then do; end; PopEnd=_popend{PerNo}; Brths=_brths{perno}; Dths=_dths{perno}; NatInc=Brths-Dths; PopChange=_popcs{perno}; NetMig=_netmig{perno}; Dmig=_dmig{perno}; Imig=_imig{perno}; output; *---1 observation per geography/interval----; end; keep SumLev fipco county PerNo Period Year PopEnd--Imig; run; proc print data=trends(obs=100) ; by fipco county; id fipco county; run;