x cd /pub/data/stf901/Tools; %let pgm=momsas00; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Oct 2001. Under contract with Mo Census Data Center. Aggregate 1990 county level data to create MSA summaries using 2000 definitions. *Rerun 3-5-02 to fix sumlev and geocode.** --> stf901.momsas00 (Metro Statistical Areas within state) --*; libname stf901 '/pub/data/stf901'; libname sf1 '/pub/data/sf12000'; libname user '/SAS_temp/user'; options msglevel=i ; options compress=yes; *---create input set for aggregation--; data aggin; merge sf1.mostcntyph(where=(sumlev='050') keep=county sumlev msacmsa pop100 rename=(pop100=pop2000) in=in2k) stf901.moi(where=(slvl='050') keep=state county slvl _numeric_ in=in90); by county; *--the sf1 set is in the merge strictly to pick up the 2000 msacmsa code, and - as an afterthought - we also picked up the 2000 pop--; if not (in90 and in2k) then do; put //'****Logic Check**** '/ _all_; abort abend; end; drop sumlev slvl; run; proc sort; by msacmsa; run; %agg(aggin=aggin,aggout=aggout,aggby=msacmsa,idvars=state, aggvars=%str(pop2000 p1i1--h55i4 ), agglvl=1, MEANS=P17AI1 H17AI1 H18AI1 H18AI2, MWEIGHTS=P2I1 H2I1 H3I1 H3I2 , grand=0) run; data stf901.momsas00(label='1990 stf1 data by 2000 defn MSAs' compress=no); length sumlev $3 areaname $40 geocode $8 state $2 msacmsa $4; set aggout; link domedians; sumlev='381'; if msacmsa ne '9999' then areaname=put(msacmsa,$metro40.); else areaname='Non Metro Remainder of State'; geocode=msacmsa||'-'||state; drop _lvl_ _nag_; label pop2000='Total Pop from SF1 2000'; return; domedians: *---code taken from the sascode(aggstf1.sas) module. Estimate percentiles using median macro--; RETAIN HV1 15000 HV2 HV3 HV4 HV5 HV6 HV7 HV8 5000 HV9 10000 HV10 15000 HV11 HV12 HV13 HV14 HV15 25000 HV16 HV17 50000 HV18 HV19 50000 HV20 200000 R1 100 R2-R14 50 R15 250 R16 500; ARRAY HVALUE HV1-HV20; *<--MEASURES OF THE "WIDTHS" OF H23 CELLS; ARRAY RENTS R1-R16; *<--MEASURES OF THE "WIDTHS" OF H32 CELLS; ARRAY NVALUE H23I1-H23I20; ARRAY NRENTS H32I1-H32I16; %MEDIAN(INTSIZE=HVALUE,INTVALS=NVALUE,Q1=H23AI1,MDN=H23BI1,Q3=H23CI1) %MEDIAN(INTSIZE=RENTS,INTVALS=NRENTS,Q1=H32AI1,MDN=H32BI1,Q3=H32CI1, SAMESTEP=1) *--ROUND ALL VALUES TO NEAREST DOLLAR--*; H23AI1=ROUND(H23AI1); H23BI1=ROUND(H23BI1); H23CI1=ROUND(H23CI1); H32AI1=ROUND(H32AI1); H32BI1=ROUND(H32BI1); H32CI1=ROUND(H32CI1); P17AI1=ROUND(P17AI1,.01); H17AI1=ROUND(H17AI1,.01); H18AI1=ROUND(H18AI1,.01); H18AI2=ROUND(H18AI2,.01); return; drop hv1-hv20 r1-r16; *<---constant values used to re-estimate medians---; run; *-------------Print Some ID fields and do some means to verify we did not lose any data------------*; proc print data=stf901.momsas00(obs=20 keep=_char_ p1i1 h1i1 h23bi1 pop2000); title2 'Sample Data from stf901.momsas00'; run; proc means data=stf901.momsas00 maxdec=0 n min max sum mean; var p1i1 pop2000; title2 'Mean Statistics Based on momsas00'; run;