x cd /pub/data/sf12000/Tools; %let pgm=aggsf1_test; filename pgm "&pgm..sas"; /*----------------------------------------------------------------------------------------------------------------- This code aggregates a set of sf12000 data sets to create summaries at different geographic levels. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Under contract with the Missouri Census Data Center Revision History: 6.05.01: Coding begins. ------------------------------------------------------------------------------------------------------*/ %libname(sf12000,opts=); libname sf1 (sf12000); libname user '/SAS_temp/user'; *---comment out. Testing complete, module renamed median and will automagically included--; *include '/pub/sas/macros/median_test.sas'; *<=====using new test version===; %macro atoI(list,x); %*--utility macro to take a list of variables containing a wild card character ("x", by defaut) and replacing it with the letters a, b, c, d, e, f, g, h, and I in order. To generate the lists used in sf1 for the race/hispanic tables.--; %if &x eq %then %let x=x; %*--default wild card character is "x"--; %sysfunc(translate(&list,a,&x)) %sysfunc(translate(&list,b,&x)) %sysfunc(translate(&list,c,&x)) %sysfunc(translate(&list,d,&x)) %sysfunc(translate(&list,e,&x)) %sysfunc(translate(&list,f,&x)) %sysfunc(translate(&list,g,&x)) %sysfunc(translate(&list,h,&x)) %sysfunc(translate(&list,I,&x)) %mend atoI; /*<=========================Comment out===================================== *----For testing purpose we select all 060 summaries in 1 county and see if we can get them to agg to the county summary data--; data agginsf1; set sf1.moph(where=(sumlev='060' and county='29001')); run; %agg(aggin=agginsf1,aggout=aggoutsf1, aggby=county, aggvars=p1i1--h16Ii19, naggvars=3060, means= p17i1 p33i1 p17ai1 p17bi1 p17ci1 p17di1 p17ei1 p17fi1 p17gi1 p17hi1 p17Ii1 p33ai1 p33bi1 p33ci1 p33di1 p33ei1 p33fi1 p33gi1 p33hi1 p33Ii1 h12i1 h12i2 h12i3 %atoI(h12xi1 h12xi2 h12xi3) , mweights=p15i1 p31i1 p15ai1 p15bi1 p15ci1 p15di1 p15ei1 p15fi1 p15gi1 p15hi1 p15Ii1 p31ai1 p31bi1 p31ci1 p31di1 p31ei1 p31fi1 p31gi1 p31hi1 p31Ii1 h4i1 h4i2 h4i3 %atoI(h15xi1 h15xi2 h15xi10) , debug=1, agglvls=1) run; data test; set aggoutsf1; **(keep=_lvl_ _nag_ p17i1 p33i1 p17ai1 p17bi1 p17ci1 p17di1 p17ei1 p17fi1 p17gi1 p17hi1 p17Ii1 %atoI(p33xi1) h12i1 h12i2 h12i3 %atoI(h12xi1 h12xi2 h12xi3) ); array aggvals{200} _temporary_; *array vars p17i1 p33i1 p17ai1 p17bi1 p17ci1 p17di1 p17ei1 p17fi1 p17gi1 p17hi1 p17Ii1 %atoI(p33xi1) h12i1 h12i2 h12i3 %atoI(h12xi1 h12xi2 h12xi3) ; *--the previous vars array was use to make sure all our means made it OK. Now we want to test medians--; array vars p13i1-p13i3 %atoI(p13xi1 p13xi2 p13xi3); *---Calculate all the age medians from the corresponding distributions. Note that we do not have explicit distrib tables for total age, but have to create the totals by summing male and female counts in each case.--; array _p12t {23} _temporary_; array _p12w {23} _temporary_ (5, 5, 5, 3, 2,1,1,3,5,5,5,5,5,5,5,2,3,2,3,5,5,5,5); * --Age intervals for table 12 are: Under 5 years 5 to 9 years 10 to 14 years 15 to 17 years 18 and 19 years 20 years 21 years 22 to 24 years 25 to 29 years 30 to 34 years 35 to 39 years 40 to 44 years 45 to 49 years 50 to 54 years 55 to 59 years 60 and 61 years 62 to 64 years 65 and 66 years 67 to 69 years 70 to 74 years 75 to 79 years 80 to 84 years 85 years and over --; option mprint; %macro domedian(r); %*--r is the race code for the table. We do the same processing on corresponding p13 and p12 tables depending on the race code. When r is blank we are working with the unqualified total-pop tables--; array _p12&r.m p12&r.i3-p12&r.i25; array _p12&r.f p12&r.i27-p12&r.i49; do _i_ = 1 to 23; _p12t{_i_}=_p12&r.m{_i_} + _p12&r.f{_i_}; end; %*--Example: when r=a then the first macro invocation says to calculate the est median variable p13ai1 by using the data distribution values in array _p12t (data from table p12a, summed over sex) and using the array _p12w of constant "interval widths" data. The second median invocation repeats this process but assigns result to p13ai2 and uses the _p12am data distribution array which is the set of male counts. And the 3rd invocation creates p13ai3 as the female median by working with the array of females counts in _p12af.---; %median(mdn=p13&r.i1,intvals=_p12t,intsize=_p12w,samestep=1) ; %*--medians for total pop-; %median(mdn=p13&r.i2,intvals=_p12&r.m,intsize=_p12w,samestep=1) ; %*--medians for males-; %median(mdn=p13&r.i3,intvals=_p12&r.f,intsize=_p12w,samestep=1) ; %*--medians for females-; %mend domedian; %domedian() ;*--Assigns p13i1, p13i2 and p13i3 using data in distribution array p12-; %domedian(a) ;*--Assigns p13ai1, p13ai2 and p13ai3 using data in distribution array p12a-; %domedian(b) ;*--etc.--; %domedian(c) %domedian(d) %domedian(e) %domedian(f) %domedian(g) %domedian(h) %domedian(I) *---Here is the testing code. We save all the aggregated medians in the aggvals array, then we read the county totals obs on the original data set. The calcuated medians should approximate the actual values. We flag cases the they differ by more than .5, though these are not necessarily mistakes.--; do over vars; aggvals{_i_}=vars; end; set sf1.moph(where=(sumlev='050' and county='29001')); do over vars; diff=abs( vars - aggvals{_i_} ); if diff > .5 then put vars= diff= +1 'Aggregated value=' aggvals{_i_}; end; output; stop; run; *----Aggregate the pct data set. We will NOT aggregate pct12r set----; data agginsf1pct; set sf1.mopct(where=(sumlev='080' and county='29001')); run; ===========================End commented out================================ */ %agg(aggin=agginsf1pct,aggout=aggoutsf1pct, aggby=county, aggvars=pop100 hu100 intptlat intptlon LandSQMI AreaSQMI pct1i1 -- pct17Ii75, naggvars=0, means= intptlat intptlon, mweights= areasqmi , debug=1, agglvls=1) run; data _null_; set aggoutsf1pct; put _all_; stop; run;