x cd /pub/data/popests/Tools; %let pgm=poptrends_casrh; filename pgm "&pgm..sas"; /*--Create the county, state and nation-level poptrends_ca datasets that will be used to create the corresponding poptrends_casrh web reports. Modeled after setup we did with the nchhsbri bridged-race single year of age data. Creates the dataset popests.ustrends2 . jgb, 6-14-10 (begin work). Reviving after neglect 6-16 w 2015 vintage data. --*/; /* filename mprint 'poptrends.mprint.sas'; options mfile; */ %let latestyr=15; %let latestyear=20&latestyr; *<====; %let nyears=%eval(5 + &latestyear - 2005); %let temp=temp; *--for embargoes data use temp=temp otherwise temp= (null) --; title "&pgm.: Pop Trends Based on the casrhi estimates for 2+ decades 90s to current"; libname user '/SAS_temp/userb'; libname nchsbri '/pub/data/popests/nchsbri' access=readonly; *<---NOT used here but as reference to how we did our model--; libname popests "/pub/data/popests/&temp"; libname alt09 '/pub/data/popests//casrhalt09' access=readonly; libname altxx "/pub/data/popests/casrhalt&latestyr" access=readonly; libname casrh99 '/pub/data/popests/casrh99' access=readonly; %let debug=0; *---optional generation of debugging info---; proc format; *---this format takes the year and returns the index in our table where we store the data for that year--; Value $yearix '1990'=1 '1995'=2 '2000'='3' '2003'=4 '2005'=5 '2006'=6 '2009'=7 '2010'=8 '2011'=9 '2012'=10 '2013'=11 '2014'=12 '2015'=13 '2016'=14 '2017'=15 '2018'=16 '2019'=17 other=0; *<==================Add another entry in 2012 !!!!=; %let nyears=13; ** Value $demog 01='Total Population' 02='White' 03='White non-hispanic' 04='Black' 05='American Indian, Etc' 06='Asian or Pac Islndr' 07='Hispanic' 08='Non-hispanic' 09='Pop Aged 0 to 17' 10='Pop Aged 18 to 24' 11='Pop Aged 25 to 44' 12='Pop Aged 45 to 64' 13='Pop Aged 65+'; Value $demog 01='Total Population' 02='White alone' 03='White alone non-hispanic' 04='Black alone' 05='American Indian, Etc alone' 06='Asian alone' 07='Hispanic' 08='Non-hispanic' 09='Pop Aged 0 to 17' 10='Pop Aged 18 to 24' 11='Pop Aged 25 to 44' 12='Pop Aged 45 to 64' 13='Pop Aged 65+' 14='Multi-racial'; run; %*let state=29; %*let stab=mo; %global decades; %let decades=199x 200x 201x; %macro doit(state,stab); %if %index(&decades,199x) %then %do; data ests19xx&stab; set casrh99.&stab.9099(rename=(hispanic=_hflag tot_pop=totpop)); where year in ('1990','1995') and slvl='050'; where also substr(racehsex,2,2)='--' or racehsex in('-1-','10-'); *--picks off ---, r--= race total, h tot and white non-hisp--; by county year; array _vars age00 age18 age25 age45 age65 total white whitenh black amind asianpi multirace hispanic nonhispanic; *---PROBLEM: In the 90s the estimates are for the old race categories before going to combinations and multirace categories--; if first.year then do over _vars; _vars=0; multirace=.; end; *--the race categories for these were the old ones, no multis--; select (racehsex); when('---') do; Total=Totpop; Age00=sum(of age0_4--age10_14) + round(.6*age15_19); Age18=round(.4*age15_19) + age20_24; Age25=sum(of age25_29--age40_44); Age45=sum(of age45_49--age60_64); Age65=sum(of age65_69--age85ovr); end; when('10-') do; whitenh=totpop; end; when('-1-') do; hispanic = Totpop; NonHispanic=Total- hispanic; end; when('1--') white=totpop; when('2--') black=totpop; when('3--') amind=totpop; when('4--') asianpi=totpop; *when('5--') _notused=totpop; *when('6--') multirace=totpop; otherwise put racehsex= '**** not allowed for in select ****'; end; if last.year then output; keep state county year age00--nonhispanic; retain age00--nonhispanic; run; /* proc print; title "temp diagnostic listing of aggin19xx"; id county year; */ run; %end; %if %index(&decades,200x) %then %do; *---Do for the 200x and 201x estimates here what we did for the 199x estimates in previous steps---; data ests20xx&stab; length State $2 County $5 year $4; set alt09.&stab.casrh_alt09(rename=(year=yr) in=inalt09 where=(yr in ('03','06','08','09','12'))) altxx.&stab.casrh_alt&latestyr(rename=(year=yr) in=inlatest); by county yr; if yr gt '02'; *--filter data for census and estbase years--*; retain state "&state"; where yr='03' or yr='06' or yr ge '08'; *--yr code has value 01 and 02 for census and estbase. 3 is 7-1-00, 8 is for 7-1-05--; array _vars age00 age15 age25 age45 age65 total white whitenh black amind asianpi multirace hispanic nonhispanic; if first.yr then do over _vars; _vars=0; end; retain age00--nonhispanic; if agegrp=0 then do; *---values are for the total pop, not just a specific age cohort---; total=Tot_pop; white=wa_male + wa_female; whitenh=nhwa_male+nhwa_female; black=ba_male + ba_female; amind=ia_male + ia_female; asianpi= aa_male+aa_female+na_male+na_female; hispanic=h_male+h_female; nonhispanic=total-hispanic; multirace=tom_male + tom_female; *--this category not available for the 90s--; end; else do; if agegrp <=3 then age00 +Tot_pop; else if agegrp=4 then do; age00 + round(TotPop*.6); age18 = round(Tot_pop*.4); *--split the 15-19 cohort--; end; else if agegrp=5 then age18 + Tot_pop; else if agegrp<=9 then age25 + Tot_pop; else if agegrp <=13 then age45 + Tot_pop; else age65 + Tot_pop; end; if last.yr then do; if inalt09 then _baseyear=2000; else if inlatest then _baseyear=2010; else put '***Logic error *** ' _all_; length _nyear 8; _nyear=_baseyear + yr -3; *--03=2000, 08=2005, .... ---; year=_nyear; output; end; keep year county state age00--nonhispanic; run; %end; %mend doit; options Mprint; %doit(29,mo) ; %***dostates(names=1,msgs=1) ; *<====generate the 51 county level 19xx and 20xx datasets. No state or nation data yet--; *---Aggregate all the county level data to get nation and state by year summaries. We want to do all the geographic agging before we run the step to create the final ustrends dataset. (Different approach than what we did with original poptrends).--; %macro cntysets(state,stab); user.ests20xx&stab user.ests19xx&stab %mend cntysets; *<---Used to reference all the 51 state county level sets----; data aggin_&pgm; set %dostates(n=51,mac=cntysets) open=defer; ****if year=:'19' then multiracial=.; *--taken care of in earlier step. And var is multirace NOT multiracial--; run; proc sort; by state county year; run; proc means data=aggin_&pgm missing noprint; class state year; types year state*year; var total age00--age65 white whitenh black amind asianpi multirace hispanic nonhispanic; output out=aggout_&pgm sum=; run; data aggout_&pgm._edited; set aggout_&pgm; if _type_=1 then do; sumlev='010'; county=' '; end; else do; sumlev='040'; county=state||' '; end; drop _: ; run; proc sort; by state county year; run; *---this dataset is going to be used as the source for a poptrends2 web application----; data popests.ustrends2(label="Trends in pop ests based on casrh data 1990 to &latestyear"); length SumLev $3 State $2; length County $5 PerNo 3 Period $12 Demographic $2 StartPop PctStart EndPop PctEnd Change PctChange AnnualizedChange AnnualizedPctChange 5; keep sumlev state county -- AnnualizedPctChange; format StartPop EndPop comma11. Change AnnualizedChange comma10. PctStart PctEnd 5.1 PctChange AnnualizedPctChange 6.1; array est(&nyears,14) _temporary_; set aggin_&pgm(in=in1) aggout_&pgm._edited; by state county year; *---We save these 13 demographic categories including all 4 race groups and the 5 broad age groups. Nothing is crossed.-; _iyr=0; *--makes it numeric-; _iyr=put(year,$yearix.); if in1 then SumLev='050'; IF _iyr=0 or ( _iyr > &nyears) THEN Do; put / '***Logic Problem assigning _iyr: ' _all_; abort abend; end; est{_iyr,1}=Total; est{_iyr,2}=white; est{_iyr,3}=whitenh; est{_iyr,4}=Black; est{_iyr,5}=AmInd; est{_iyr,6}=AsianPI; est{_iyr,7}=Hispanic; est{_iyr,8}=NonHispanic; est{_iyr,9}=age00; est{_iyr,10}=age18; est{_iyr,11}=age25; est{_iyr,12}=age45; est{_iyr,13}=age65; est{_iyr,14}=Multirace; ***Value $yearix '1990'=1 '1995'=2 '2000'='3' '2003'=4 '2005'=5 '2006'=6 '2009'=7 '2010'=8 '2011'=9 '2012'=10 '2013'=11 '2014'=12 '2015'=13 '2016'=14 '2017'=15 '2018'=16 '2019'=17 ***; if last.county then do; *---here is where we build and write the output, a series of time-period trend summaries for the current geographic area. (County includes state here)---; State=substr(county,1,2); do _idemog=1 to 14; Demographic=put(_idemog,z2.); *<---demographic category code. 2-char with leading 0. See format code, above.--; PerNo=1; Period="1990 to &latestyear"; _periodLen=&latestyear - 1990; StartPop=est{1,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{1,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=2; Period="1990 to 2000"; _periodLen=10; StartPop=est{1,_idemog}; EndPop=est{3,_idemog}; _starttot=est{1,1}; _endtot=est{3,1};link trendcode; PerNo=3; Period="1990 to 1995"; _periodlen=5; StartPop=est{1,_idemog}; EndPop=est{2,_idemog}; _starttot=est{1,1}; _endtot=est{2,1}; link trendcode; PerNo=4; Period="1995 to 2000"; _periodlen=5; StartPop=est{2,_idemog}; EndPop=est{3,_idemog}; _starttot=est{2,1}; _endtot=est{3,1}; link trendcode; PerNo=5; Period="2000 to &latestyear"; _periodlen=&latestyr; StartPop=est{3,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{3,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=6; Period="2000 to 2005"; _periodlen=5; StartPop=est{3,_idemog}; EndPop=est{5,_idemog}; _starttot=est{3,1}; _endtot=est{5,1}; link trendcode; PerNo=7; Period="2005 to 2010"; _periodlen=5; StartPop=est{5,_idemog}; EndPop=est{8,_idemog}; _starttot=est{5,1}; _endtot=est{8,1}; link trendcode; PerNo=8; Period="2000 to 2003"; _periodlen=3; StartPop=est{3,_idemog}; EndPop=est{4,_idemog}; _starttot=est{3,1}; _endtot=est{4,1}; link trendcode; PerNo=9; Period="2003 to 2006"; _periodlen=3; StartPop=est{4,_idemog}; EndPop=est{6,_idemog}; _starttot=est{4,1}; _endtot=est{6,1}; link trendcode; PerNo=9; Period="2006 to 2009"; _periodlen=3; StartPop=est{6,_idemog}; EndPop=est{7,_idemog}; _starttot=est{6,1}; _endtot=est{&7,1}; link trendcode; _periodlen=1; do _ix=5 to &nyears -1; length _yearlow _yearhi $4; length _yearlow _yearhi $4; _yearlow=2000+_ix; _ixp1=_ix+1; _yearhi=2001+_ix; PerNo=PerNo+1; Period=_yearlow||' to '||_yearhi; StartPop=est(_ix,_idemog); EndPop=est{_ixp1,_idemog}; _starttot=est{_ix,1}; _endtot=est{_ixp1,1}; link trendcode; end; end; *---the _idemog loop in which we ouput a set of trends for for each of the specified demographic categories-; *----We could "blank out" the est array here but it should not be necessary-------------------------; end; *---last.county processing---; return; trendcode: Change=EndPop - StartPop; if StartPop then PctChange=100*Change/StartPop; else PctChange=.; PctStart=StartPop*100/_starttot; PctEnd=EndPop*100/_endtot; if _periodlen ne . and StartPop then do; AnnualizedChange=Change/_periodLen; AnnualizedPctChange= 100*((Endpop/StartPop)**(1/_periodLen)-1); end; else do; AnnualizedChange=.; AnnualizedPctChange=.; *---why repeat what is already shown as the value for the 1-year interval?-; end; output; if &debug then if length(county)=2 then put / _all_; return; run; proc freq data=popests.ustrends2; tables demographic PerNo*period/list; tables state sumlev county ; format county $county. demographic $demog.; title2 "Freq Reports on popests.ustrends2"; run ;