x cd /pub/data/sf12000/Tools; %let pgm=aggsf1_stltras; filename pgm "&pgm..sas"; /*----------------------------------------------------------------------------------------------------------------- This code aggregates sf12000 data to the St. Louis MSA (5-county subset) area for TRAs. It creates dataset sf12000.stltras. Coded by John Blodgett, OSEDA, U. of Missouri, blodgettj@umsystem.edu Under contract with the Missouri Census Data Center Revision History: 6.15.02: Coding begins. ------------------------------------------------------------------------------------------------------*/ %let setname=stltras; libname sf1 '/pub/data/sf12000'; libname user '/SAS_temp/user'; *<===Optional. Permissions on this directory limit who can use it; libname corrlst '/pub/data/corrlst'; title 'sf12000 Aggregation Run: To 5-County St. Louis MSA Area Tract Areas'; options msglevel=i; %macro atoI(list,x); %*--utility macro to take a list of variables containing a wild card character ("x", by default) 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; data agginsf1(compress=yes); length sumlev $3 tra $4; merge corrlst.tr2k2stltra(keep=county tract tra traname in=ingeos) sf1.moph(in=insf1 where=(sumlev='140' and county in ('29071','29099','29183','29189','29510'))); by county tract; if not (ingeos and insf1) then do; if pop100 =0 then delete; *<--we have some trivial tracts that need to be ignored---; put //'*******************PROBLEM!!!!!!!!!!!!!!!!!!!!!!: Data Missing on One of the files!!!!! '/ county= tract= ingeos= insf1=; abort abend; end; *---Output once for each tra type--; keep sumlev tra traname county _numeric_; run; proc sort data=agginsf1; by sumlev county tra; run; options compress=yes; *<---to get the aggregated output set to be compressed--; %agg(aggin=agginsf1,aggout=aggoutsf1, aggby=sumlev county tra, idvars=traname, aggvars=pop100 hu100 p1i1--h16Ii19 IntPtLon IntPtLat AreaSQMI, naggvars=, means= IntPtLon IntPtLat 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=p1i1 p1i1 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 &setname.ph; length sumlev $3 geocode $8 puma $3 tra $4 county $5 areaname $40 ; set aggoutsf1; *--we use a format code lookup table to assign the special 3-character "puma" codes used to organize the tras within counties.--; sumlev='tra'; puma=put(tra,$trapuma.); geocode=puma||'-'||tra; areaname=traname; drop traname; drop _lvl_ _nag_ ; label tra='Tract Area (TRA)' ; format intptlon 11.6 intptlat 10.6; *---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); option NOmprint; %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) drop _haf -- _slot2; *--temp vars used by median macro--; run; proc sort data=&setname.ph out=sf1.&setname.ph(label='St Louis Metro Tract Areas - P & H Tables') ; by puma tra; run; *---verify that the total pops agg to correct county totals---; proc means data=sf1.&setname.ph(keep=county pop100) sum n min max mean; class county; var pop100; title2 "Means of sf1.&setname.ph, by County"; run; *-----------------------Part 2: Aggregate the pct tables.-------------------------------------- ; data agginpct; merge corrlst.tr2k2stltra(keep=county tract tra traname in=ingeos) sf1.mopct(in=insf1 where=(sumlev='140' and county in ('29071','29099','29183','29189','29510')) keep=sumlev county tract pop100 hu100 pct1i1 -- pct17Ii75); by county tract; if not (ingeos and insf1) then do; if pop100 = 0 then delete; put //'*******************PROBLEM!!!!!!!!!!!!!!!!!!!!!!: Data Missing on One of the files!!!!! '/ county= tract= ingeos= insf1=; abort abend; end; sumlev='tra'; keep tra county sumlev traname _numeric_; run; proc sort data=agginpct; by tra; run; *----Aggregate the pct table data by the tras----; %agg(aggin=agginpct,aggout=aggoutpct, aggby=tra , idvars=sumlev county traname, aggvars=pop100 hu100 pct1i1 -- pct17Ii75, naggvars=1920, dropvars=_lvl_ _nag_, agglvls=1) run; data &setname.pct; length sumlev $3 geocode $8 puma $3 tra $3 county $5 areaname $40 ; set aggoutpct; *--we use a format code lookup table to assign the special 3-character "puma" codes used to organize the tras within counties.--; sumlev='tra'; puma=put(tra,$trapuma.); geocode=puma||'-'||tra; areaname=traname; drop traname; run; proc sort data=&setname.pct out=sf1.&setname.pct(label='St Louis Metro Tract Areas - PCT Tables') ; by puma tra; run; proc means data=sf1.&setname.pct(keep=county pop100) sum n min max mean; class county; var pop100; title2 "Means of sf1.&setname.pct, by County"; run;