x cd /pub/data/stf903/Tools; %let pgm=moschls00; filename pgm "&pgm..sas"; *--Coded by John Blodgett, OSEDA, Nov 2002. Under contract with Mo Census Data Center. Aggregate the previously aggregated mosl090_00 dataset (1990 data aggregated to 2000 SumLev 090 geography) to create 1990 data by 2000 Missouri School Districts (elementary and unified). Creates the datasets: stf903.moschls00 (complete districts, 2000 geographic defn. but 1990 data), stf903.moschlcos00 (similar to above for for districts split by counties). --*; libname stf903 '/pub/data/stf903'; libname user '/SAS_temp/user'; libname corrlst '/pub/data/corrlst' access=readonly; %libname(mable2k); %libname(stf901x2); %let sbg_geos=county cousubfp placefp tract UrbanRur bg ; *---2000 defn. The vars that correspond to sumlev 090--; %let sbg_geos_nour=county cousubfp placefp tract bg ; *---2000 defn. The vars that correspond to sumlev 090--; options compress=yes msglevel=i; *---We already have split-BG-2000 to school district equiv files that we used to allocate the 2000 SF3 data to districts. But the allocation factors on those lists were based on 2000 pop counts. We need comparable lists but with afacts based on 1990 pops. So here we go.... ; /*<=========================Comment out===================================== data sortin/view=sortin; merge stf901x2.moblks00(keep=county cousubfp placefp tract block bg sdelm sduni totpop rename=(totpop=pop90) in=in901x ) mable2k.moblks2(keep=county tract block ur rename=(ur=urbanrur) in=inmable); by county tract block; if in901x; *---This did NOT work -- too many blocks missing from the moblks00 dataset ---; if not (in901x and inmable) then do; put in901x= inmable= county= tract= block= pop90= ; _nbad+1; drop _nbad; if _nbad ge 200 then abort abend; delete; end; run; proc sort data=sortin out=blkcodes; by &sbg_geos sduni; run; *--We use the corrwt utility macro to create the correlation lists by collapsing--; %corrwt(setin=blkcodes,setout=sbg2k_sduni_wt90, geocds1=&sbg_geos, geocds2=sduni, weight=pop90, keepwt=1); proc sort data=blkcodes; by &sbg_geos sdelm; run; %corrwt(setin=blkcodes,setout=sbg2k_sdelm_wt90, geocds1=&sbg_geos, geocds2=sdelm, weight=pop90, keepwt=1); ===========================End commented out================================ */ *--create data to be aggregated by joining the 1990 split-bg (090) level data with the 2 correlation lists, then concatenating the 2 datasets (unified and elementary data)--; data aggin1(drop=cousubfp placefp tract UrbanRur bg ) unmatched1(keep=_character_ p1i1 pop90 compress=no); length State $2 ncescode $5 ; length default=5; retain SumLev 'sdu'; merge stf903.mosl090_00(keep=&sbg_geos _numeric_ in=instf3 ) sbg2k_sduni_wt90(in=inclist where=(afact gt 0) ); by &sbg_geos; State=substr(county,1,2); if not (instf3 and inclist) then do; if instf3 and p1i1 = 0 then delete; if not instf3 and pop90=0 then delete; _nbad +1; ***if _nbad gt 100 then abort abend; drop _nbad; if instf3 or _nbad le 25 then put / '*** ' sumlev= instf3= inclist= p1i1= pop90= &sbg_geos; output unmatched1; delete; end; ncescode=sduni; output aggin1; keep sumlev ncescode &sbg_geos state _numeric_; run; data aggin2(drop=cousubfp placefp tract UrbanRur bg ) unmatched2(keep=_character_ p1i1 pop90 compress=no); length State $2 ncescode $5 ; length default=5; retain SumLev 'sde'; merge stf903.mosl090_00(keep=&sbg_geos _numeric_ in=instf3 ) sbg2k_sdelm_wt90(in=inclist where=(afact gt 0)); ; by &sbg_geos; State=substr(county,1,2); if not (instf3 and inclist) then do; if instf3 and p1i1 = 0 then delete; if not instf3 and pop90=0 then delete; _nbad +1; ***if _nbad gt 100 then abort abend; drop _nbad; if instf3 or _nbad le 25 then put / '*** ' sumlev= instf3= inclist= &sbg_geos; output unmatched2; delete; end; ncescode=sdelm; output aggin2; keep sumlev ncescode &sbg_geos state _numeric_; run; proc datasets library=user nolist; modify aggin1; index delete _all_; index create aggby=(SumLev ncescode county); modify aggin2; index delete _all_; index create aggby=(SumLev ncescode county); quit; data aggin; set aggin1 aggin2 ; by sumlev ncescode County; run; *----We use the module in sascode(agg903.sas) to do the aggregation, but we have to assing the global parms used by that module so it knows where things come from and go to. ----*; %let _aggin=aggin; %let _aggout=aggout; %let _aggby=sumlev ncescode county; %let skipagg=0; %let _grand=0; %let _agglvl=3; %let _idvars=State; %let _facvar=afact; %include '/pub/sascode/agg903.sas'/source2; *<---include standard sas code to do the actual aggregation based on all the global parms just assigned. Includes a post step to handle medians----; *drop areaname; run; data stf903.moschls00(label='1990 stf3 tables by complete 2000 Legislative Districts' drop=county cnty partflag) stf903.moschlcos00(label='1990 stf3 tables by 2000 Legislative Districts by County') cksums(compress=no); length sumlev $3 AreaName $40 geocode $11 DeseDist $6 county $5 cnty $3 ncescode $5 partflag $1; set aggout; by sumlev ncescode notsorted county notsorted _lvl_ notsorted; if _lvl_=3 then do; file log; put '***Check sum:' sumlev= p3i1= pop90=; output cksums; delete; end; select (sumlev); when('sde') do; if ncescode='99999' then areaname='Not in any elementary district'; else areaname=put(ncescode,$school.); end; when('sdu') do; if ncescode='99999' then areaname='Not in any unified district'; else areaname=put(ncescode,$school.); end; end; desedist=put(ncescode,$schcnvt.); *--add dese codes and the dist name-; if _lvl_=1 then do; *--its a district within county sum--; if SumLev='sdu' then SumLev='su2'; else SumLev='se2'; geocode=ncescode||'-'||county; cnty=substr(county,3,3); *--See if it is split across counties--; if not (first._lvl_ and last._lvl_) then do; partflag='y'; areaname=trim(areaname)||'/'||put(cnty,$mocnty.); end; else partflag='n'; output stf903.moschlcos00; end; else do; *--_lvl-=2 -- a complete-district total --; geocode=ncescode; if ncescode ne '99999' then output stf903.moschls00; end; label ncescode='NCES School District Code' desedist='Mo Dept of Elem & Sec Educ. District Code' partflag='District Spans Counties?'; drop _lvl_ _nag_; run; *---Create some indices on the moschls00 set---; proc datasets library=stf903; modify moschls00; index create desedist; index create geocode; index create slgeo=(sumlev geocode); quit; *---run a district by district compare with the stf901 data---; data compare; merge stf901x2.moschls00(keep=sumlev geocode areaname totpop rename=(totpop=sf1pop) in=insf1) stf903.moschls00(keep=sumlev geocode areaname p3i1 pop90 in=insf3); by geocode; where geocode ne '99999'; if not (insf1 and insf3) then put / '*****Observation Mismatch**** ' _all_; else do; diffpop=round(sf1pop - p3i1); format sf1pop p3i1 comma9. diffpop comma5.; end; run; proc sort; by areaname; run; proc print data = compare; sum sf1pop p3i1 diffpop pop90; title2 'Difference Report Showing sf1 and sf3 Pops by District'; run; *---check step to see if total pops for each legtype sum to state total pop--; proc means data=stf903.moschls00 n sum; var p3i1; where ncescode ne '99999'; *class sumlev; run; proc tabulkate data=stf903.moschlcos00; var p3i1 pop90; class sumlev county; table sumlev*(all county), (p3i1 pop90)*(n*f=4. sum*f=comma9.); title2 'Table from stf903.moschlcos00'; run;