x cd /pub/data/stf901/Tools; %let pgm=mozips00; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Oct 2001. Under contract with Mo Census Data Center. Aggregate/convert 1990 full stf1 data set at the (1990) census block level to create: --> stf901.mozips00 (complete ZIP codes or ZCTAs: 2000 geographic defn but 90 data) and --> sftf901.mozipcos00 (similar to above but for ZIPs/ZCTAs split by counties). --*; libname stf901 '/pub/data/stf901'; libname user '/SAS_temp/user'; options msglevel=i ; options compress=yes; /*<=========================Comment out===================================== *---create input set for aggregation--; proc datasets library=stf901 nolist; modify moblks00; index create zipcnty=(zcta5 county); quit; %agg(aggin=stf901.moblks00,aggout=aggout,aggby=zcta5 county, aggvars=%str(p1i1--h55i4), agglvl=2, MEANS=P17AI1 H17AI1 H18AI1 H18AI2, MWEIGHTS=P2I1 H2I1 H3I1 H3I2 , grand=1) run; ===========================End commented out================================ */ data stf901.mozips00(label='1990 stf1 data by complete 2000 ZIP/ZCTA Geo' drop=partflag county cnty sortedby=zcta5 compress=yes) stf901.mozipcos00(label='1990 stf1 by 2000 ZIP/ZCTA within Counties' sortedby=zcta5 county compress=yes); length sumlev $3 areaname $56 geocode $12 ZCTA3 $3 ZCTA5 $5 state $2 county $5 cnty $3 partflag $1; set aggout (where=(_lvl_ ne 99)); by zcta5 _lvl_ notsorted; link domedians; state='29'; *<---------------------was not on input set so we have to define it here------------------------; ZCTA3=substr(zcta5,1,3); if _lvl_=1 then do; *--its a zcta5 within county sum--; sumlev='881'; areaname='ZCTA '||ZCTA5; cnty=substr(county,3,3); geocode=state||'-'||zcta5||'-'||cnty; *--See if it is split across counties--; if not (first._lvl_ and last._lvl_) then do; partflag='y'; areaname=trim(areaname)||'/'||trim(put(cnty,$mocnty.))||' part';; end; else partflag='n'; output stf901.mozipcos00; end; else do; *--_lvl_=2: complete zcta summary-; partflag=' '; sumlev='871'; geocode=state||'-'||zcta5; areaname='ZCTA '||zcta5; output stf901.mozips00; end; label ZCTA5='ZIP Census Tab Area, 2000' partflag='ZIP Spans Counties?'; drop _lvl_ _nag_; 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; %macro sorts; proc sort data=stf901.mozips00; by zcta5; run; proc sort data=stf901.mozipcos00; by zcta5 county; run; %mend sorts; *-------------Print Some ID fields and do some means to verify we did not lose any data------------*; proc print data=stf901.mozips00(obs=20 keep=_char_ p1i1 h1i1 h23bi1); title2 'Sample Data from stf901.mozips00'; run; proc means data=stf901.mozips00 maxdec=0 n min max sum mean; var p1i1; title2 'Mean Statistics Based on mozips00'; run; proc print data=stf901.mozipcos00(obs=20 keep=_char_ p1i1 h1i1 h23bi1); title2 'Sample Data from stf901.mozipcos00'; run; proc means data=stf901.mozipcos00 maxdec=0 n min max sum mean; var p1i1; title2 'Mean Statistics Based on mozipcos00'; run; proc datasets library=stf901 nolist; modify mozips00; index create geocode; modify mozipcos00; index create geocode; index create county; quit;