x cd C:\Users\riceg\Desktop\NCHSBRI; %let pgm=nchsbridged_sumry; filename pgm "&pgm..sas"; ods listing; ods results; *---collapse the detailed nchsbridged data by single yrs of age, race, sex and hispanic to create 1 obs per geographic area and age (still single year). For both 20xx and 19xx datasets in /pub/data/popests/nchsbri . See setups in cnvt_nchs_bridged.sas and cnvt_nchs_bridged90s.sas to see how we created the input datasets used here. And in cnvt_usnchsbridged200x_intrcnsl !! (Oct. 2012) jgb, 12-05. Running 8-28-06 with new cycle of estimates thru 2005. Running 9/09 with new cycle of estimates thru 2008. Running 9/10 with new cycle of estimates thru 2009. IMPORTANT NOTE: We changed permissions on the 20xx_sumry datasets so that they can NOT be written over. If need to regen these it will first require doing: chmod 664 *20xx_sumry.sas7bdat . Added code to copy mo subset to popests as well as to nchsbri lib. 1-11 (run interactively). 10-12: Running to access the new 2000-2009 intercensal estimates just released. 08-13: Running with 2012 vintage data. Running a 2nd time after finding a bug in cnvt_nchs_bridged_201x.sas . 06-14: Running with 2013 vintage data. 07-15: Running with 2014 vintage data. 07-16: Running with 2015 vintage data. ---*; **libname user '/SAS_temp/userb'; libname nchsbri 'C:\Users\riceg\Desktop\NCHSBRI\out' outrep='LINUX_X86_64'; libname popests 'M:\pub\data\popests'; %let dec=201; *<---indicates decade being processed---; %let lyear=2016; *<===========parm indicates latest year for which estimates are available on input---; %let lyr=%substr(&lyear,3,2); /* =======================Begin comment================ %let state=29; %let stab=mo; %let stname=Missouri; ======================End comment================== */ %macro doit(state,stab); %global dec lyear lyr; %local setsfx; %if &dec=%str() %then %let dec=19; %if &dec=19 %then %do; %let year1=1990; %let lyear=1999; %end; %else %if &dec=20 %then %do; %let year1=2000; %let lyear=2009; %let lyr=09; %end; %else %if &dec=201 %then %let year1=2010; *<-----; %let yr1=%substr(&year1,3,2); %if &dec=19 %then %let setsfx=19xx; %else %if &dec=201 %then %let setsfx=201x; %else %if &dec=20 %then %let setsfx=20xxi; *<====We add the "i" now when using intercensal estimates--; title "Create nchsbri.&stab.nchsbridged&setsfx._sumry"; ***** From Data in nchsbri.&stab.nchsbridged&setsfx; data sumryin; %if &dec=20 %then %do; set nchsbri.usnchsbridged200x_intrcnsl (where=(state="&state")); *<====new===; %end; %else %do; set nchsbri.&stab.nchsbridged&setsfx; %end; Length Year $4 default=5 ; retain _lyear "&lyear"; array est(*) popjl&yr1 - popjl&lyr; _k=0; do _year=&year1 to &lyear; Year=_year; _k+1; Estimate=est{_k}; link output; end; keep County Year Age Race Sex Hispanic Estimate; return; output: output; _save=county; county="&state. "; output; *<--- to get state totals---; county=_save; return; drop _: ; run; proc sort; by County Year Age; run; proc summary data=sumryin ; by county year; class age race sex hispanic; var estimate; types age*race*hispanic age*sex race*hispanic sex ; output out=sumryout sum= ; run; proc sort; by county year age _type_; run; data nchsbri.&stab.nchsbridged&setsfx._sumry(label="Demographic totals &statenm state & counties by total & single yrs of age & Yr of estimate" index=(county)); length State $2; set sumryout(rename=(hispanic=hispanicIn)); retain SumLev ' '; by county year age ; length Age_cohort1 Age_cohort2 $2 default=5; retain age_cohort1 age_cohort2; if first.county then if county="&state. " then SumLev='040'; else SumLev='050'; array _count(*) Total Male Female White WhiteNH Black BlackNH AmInd AmIndNH AsianPI AsianPINH Hispanic NonHispanic; State=substr(county,1,2); if first.age then do _i=1 to dim(_count); _count{_i}=0; *--define the age_cohort variables which will facilitate aggregating to these intervals---; if age=' ' then age_cohort1=' '; else if age le '17' then age_cohort1='00'; else if age le '24' then age_cohort1='18'; else if age le '44' then age_cohort1='25'; else if age le '64' then age_cohort1='45'; else age_cohort1='65'; length _agec2 8; if age=' ' then age_cohort2=' '; else do; _agec2=int(input(age,2.)/5)*5; age_cohort2=put(_agec2,z2.); end; end; if Race ne ' ' then do; if hispanicIn='1' then _rnhest=Estimate; else _rnhest=0; select(Race); when ('1') do; White + Estimate; WhiteNH + _rnhest; end; when ('2') do; Black + Estimate; BlackNH + _rnhest; end; when ('3') do; AmInd + Estimate; AmIndNH + _rnhest; end; when ('4') do; AsianPI + Estimate; AsianPINH + _rnhest; end; end; *--when race is not blank it indicates a race*hispanic combination---; if HispanicIn='2' then Hispanic + Estimate; else NonHispanic + Estimate; end; else if Sex ne ' ' then do; if Sex='1' then Male + Estimate; else Female + Estimate; end; else do; _nerr+1; if _nerr=1 then put // '*****Logic Errors Found****** '; if _nerr le 10 then put / _all_; else abort abend; end; cklast: if last.age then do; Total=Male + Female; output; end; keep SumLev State county year age age_cohort: Total White--AsianPINH Male Female Hispanic NonHispanic; label age_cohort1='Broad age Cohort: 0-17,...,65+' age_cohort2='5-yr Cohort: 0-4,...,85+'; label year='Estimate is as of July of this year' White='White Persons (bridged race)' AmInd='American Indian, Esk, Aleut (bridged race)' WhiteNH='White non-hispanic Persons (bridged race)' Black='Black Persons (bridged race)' BlackNH='Black non-hispanic Persons (bridged race)'; run; proc print data=nchsbri.&stab.nchsbridged&setsfx._sumry (obs=150) ; by Sumlev State county; id year age; where age le '05' and year in ("&year1","&lyear") and county in ("&state","&state.001") ; title2 "Selected Observations from nchsbri.&stab.nchsbridged&setsfx._sumry"; run; %if &state=29 %then %do; data popests.monchsbridged&setsfx._sumry; set nchsbri.monchsbridged&setsfx._sumry; run; %end; %mend doit; %macro dostates( /*--This macro is used as a "driver" to invoke a user-defined macro once for every state in the US or for every state whose FIPS code appears in the listfps parameter. By default it will loop for all states including DC. Specify N=50 to omit DC and specify N=57 to get the 6 territories as well (PR, GU, VI,etc). The macro invokes the user-specified macro (default name is "doit") and passed 2 positional parm values: the first is the state fips code, the 2nd the state postal abbreviation in lower case. The user-defined macro is named "doit" by default (value of mac parm will override). This macro should have 2 positional parms, the first for the state fips code (2-digit with leading 0) and the 2nd for the std 2-char postal abbreviation. ---- */ listfps, /* list of state fips code to process. If left blank it will be implied based on value of n parm. If n is not specified, it defaults to 51 and this parm is assigned a value of 01 02 04 05 ... i.e., a list of all 50 state codes and DC */ revdate=12/31/2003, n=51, /* number of states to process. Only used if listfps is left blank, in which case we have 3 specially recognized values: 51, to mean do all states + DC. 52, to mean all states, DC and PR (new 5/09) 50, meaning do all states but not DC. 57, means do all 50 states, DC and the 6 territories as well. If you specify your own list of state codes (listfps parm) the macro will calculate N as the number of codes in your list */ mac=doit, /* name of the user-written macro that will be invoked once for each of the state codes specified via the listfps/n parameters */ msgs=0, /* specify msgs=1 to have a message generated on the log to signal the start of each invocation of the user-written macro */ names=0, /* specify names=1 to have the macro declare and assign a value to the global variable statenm which will contain the mixed-case name of the state during each cycle. So, if you are processing Iowa and you specified names=1 then your macro will be able to use a statement such as :%put ***Begin processing &statenm ***. */ debug=0 ); %*--- Revision History: 7-31-99: Adding determining of state name from state code via sysfunc/fipnamel. 11-14-99: Cleaning up the comments to make it useful to other people. 11-17-99: Trivial change in comment describing names option. (NOTE: update value of revdate parm!!) --*; %if &msgs %then %put ***dostates macro, rev. &revdate, Begin Execution***; %local stabs stabs2 stfps stfps2; %local _state _stab; %let stabs=al ak az ar ca co ct de dc fl ga hi id il in ia ks ky la me md ma mi mn ms mo mt ne nv nh nj nm ny nc nd oh ok or pa ri sc sd tn tx ut vt va wa wv wi wy; %let stfps=01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56; %let stabs2=as gu mp pw pr vi; %let stfps2=60 66 69 70 72 78; %if &n=57 %then %do; %let stfps=&stfps &stfps2; %let stabs=&stabs &stabs2; %end; %if &n=52 %then %do; %let stfps=&stfps 72; %let stabs=&stabs pr; %end; %if &listfps eq %str() %then %let listfps=&stfps; %else %let n=%eval( %eval(%length(&listfps)+1) /3); %local i_; %if &names %then %do; %global statenm; %end; %*--Here is the macro invocation loop--------------------------------------*; %let nlast=&n; %if &nlast=50 %then %let nlast=51; %do i_=1 %to &nlast; %let _state=%scan(&listfps,&i_); %if &listfps=&stfps %then %let _stab=%scan(&stabs,&i_); %else %do; %local _ix; %let _ix=%index(&stfps&stfps2,%trim(&_state)); %let _stab=%substr(&stabs&stabs2,&_ix,2); %put ** dostates macro looping with: i_= &i_ _ix= &_ix _stab= &_stab; %end; %if &names %then %let statenm=%sysfunc( fipnamel(&_state)); %else %let statenm= ; %if &debug %then %do; %put **temp debug msg: Value of var n is &n %str( ) value of var _stab is &_stab ****; %end; %if &n=50 and %superq(_stab)=dc %then ; %else %do; %if &msgs %then %put ****&mac being invoked for state &_state &_stab &statenm ****; %&mac(&_state,&_stab) %end; %end; %mend dostates; options Mprint; %**let dec=19; %**let dec=20; %*---the &dec parm is specified at top of this file. (Probably value is 201).----; options NOmprint; /* ========================begin comment==================================== %dostates(10,names=1); *---Do Delaware test run---; %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25,names=1); %dostates(26 27 28 29 30 31 32 33 34 35 36 37 38,names=1); %dostates(39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56,names=1); ==========================end comment====================================== */ %dostates(n=51,names=1);