x cd /pub/data/sf32000/Tools; %let pgm=agg_moschls; filename pgm "&pgm..sas"; *---2-2-2010: Following loss of custom- moschl datasets we regenerate them via our usual allocate and aggregate process. Mo only. --; title "&pgm.: Allocate sf32000 Data to Missouri School Districts"; libname sf32000 '/pub/data/sf32000'; libname xxsl090 '/pub/data/sf32000/xxsl090'; %libname(mable2k); libname temp '/pub/data4/temp'; libname corrlst '/pub/data/corrlst'; libname sf1geos '/pub/data/sf12000/xxgeos'; title "&pgm : Allocate and aggregate sf32000 data to create moschlsph, moschlsphct and moschlphctr Datasets"; %let bgkeys=county cousubfp placefp tract urbanrur bg; %let trkeys=county cousubfp placefp tract urbanrur; /* =======================Begin comment================ *----Step 0: Create new and improved equivalency files at the split-tract (sumlev=085) and split-BG (sumlev=090) with both levels of school and with new variables distype and desecode. Note that sduni and sdelm are mutually exclusive in Missouri. There are no blocks containing both codes (non 99999) ---; data temp.moblks2schools; merge sf1geos.moblks (keep=&bgkeys block sdelm sduni pop100 where=(pop100) in=inblks) mable2k.moblks2a(keep=county tract block ur in=ina); by county tract block; if inblks; if not ina then do; _bad+1; if _bad le 20 then put / _all_; else abort abend; end; urbanrur=ur; *<---the urbarnrur variable was not filled in on the sf1 header files in 2001 because it had not been determined yet. So we have to get it from a later source.---; if sdelm ne '99999' then do; SumLev='sde'; ncescode=sdelm; end; else do; SumLev='sdu'; ncescode=sduni; end; output; drop ur _: ; run; proc sort; by &bgkeys ncescode; run; proc datasets library=temp; modify moblks2schools; ***index create bgkeys =(&bgkeys ncescode); index create trkeys =(&trkeys ncescode); quit; %corrwt(setin=temp.moblks2schools,g1=&bgkeys,g2=ncescode,idvars=sumlev,weight=pop100,keepwt=1,setout=corrlst.mosbg2schl2k) proc print data=corrlst.mosbg2schl2k(obs=200); by county; title2 "&syslast"; run; %corrwt(setin=temp.moblks2schools,g1=&trkeys,g2=ncescode,idvars=sumlev,weight=pop100,keepwt=1,setout=corrlst.mostr2schl2k) proc print data=corrlst.mostr2schl2k(obs=200); by county; title2 "&syslast"; run; ======================End comment================== */ %Macro preexit; %mend; %Macro postexit; if ncescode ne '99999' then areaname=put(ncescode,$school.); else select(sumlev); when('se2') areaname='Not in an Elementary District'; when('su2') areaname='Not in a Unified District'; end; by _lvl_ notsorted; *<---; if _lvl_=1 then do; *--this is a district within county summary--; geocode=ncescode||'-'||county; if sumlev='sdu' then sumlev='su2'; else sumlev='se2'; if not (first._lvl_ and last._lvl_) then do; partflag='y'; areaname=trim(areaname)||'/'||put(county,$mocnty.); end; else partflag='n'; end; else do; *--this is a complete district (_lvl_=2) summary--; **if sumlev='su2' then sumlev='sdu'; **else sumlev='sde'; partflag=' '; geocode=ncescode; county=' '; end; cnty=substr(county,3,3); label ncescode='NCES School District Code' desedist='Mo Dept of Elem & Sec Educ. District Code'; desedist=put(ncescode,$schcnvt.); *--add dese codes---; length desecnty $3; desecnty=substr(desedist,1,3); *<---new variable 2/10---; drop afact _: ; %mend postexit; /* =======================Begin comment================ data temp.agginph; length state $2; merge xxsl090.moph(in=insf3 where=(pop100)) corrlst.mosbg2schl2k(in=inclist); by &bgkeys ; state='29'; *<---; if not (insf3 and inclist) then do; _nbad+1; if _nbad le 20 then put insf3= inclist= pop100= afact= +1 &bgkeys; if _nbad ge 100 then abort abend; if insf3; end; *--Calculate 2 new universe variables needed for aggregating. These are the 100 pct counts for occupied and vacant hus-; if H4i1 then H3i2=100*(H2i2/H4i1); *--100% count of occ units is occ units sampled divided by pct occ units sampled-; if H4i2 then H3i3=100*(H2i3/H4i2); *--100% count of vac units is vac units sampled divided by pct vac units sampled-; label H3i2='100% Count of Occupied hus (derived)' H3i3='100% Count of Vacant units (derived)'; drop PCT; *--this was a little flag var we set which is irrelevant after aggregation-; keep &bgkeys state ncescode sumlev _numeric_; run; proc datasets library=temp nolist; modify agginph; index create schlco=(ncescode county); quit; proc means data=temp.agginph sum ; class state county; var pop100; run cancel; *<---just a test for early run to make sure...--; ======================End comment================== */ /* =======================Begin comment================ data temp.agginphct; length state $2; merge sf32000.mophct(in=insf3 where=(sumlev='085' and pop100)) corrlst.mostr2schl2k(in=inclist); by &trkeys ; state='29'; *<---; if not (insf3 and inclist) then do; _nbad+1; if _nbad le 20 then put insf3= inclist= pop100= afact= +1 &trkeys; if _nbad ge 100 then abort abend; if insf3; end; keep &trkeys state ncescode sumlev _numeric_; run; proc datasets library=temp nolist; modify agginphct; index create schlco=(ncescode county); quit; proc means data=temp.agginphct sum ; class state county; var pop100; run ; *<---just a test for early run to make sure...--; options nomprint; data temp.agginphctr; length state $2; merge sf32000.mophctr(in=insf3 where=(sumlev='085' and pop100)) corrlst.mostr2schl2k(in=inclist); by &trkeys ; state='29'; *<---; if not (insf3 and inclist) then do; _nbad+1; if _nbad le 20 then put insf3= inclist= pop100= afact= +1 &trkeys; if _nbad ge 100 then abort abend; if insf3; end; keep &trkeys state ncescode sumlev _numeric_; run; proc datasets library=temp nolist; modify agginphctr; index create schlco=(ncescode county); quit; ======================End comment================== */ *----Here we aggregatre work.agginph by ncescode/county to create sf32000.moschlsph----; %aggsf3( settypes=ph phct phctr, naggvarsph=5566, naggvarsphct=4392, naggvarsphctr=6570, steps=agg post, setinlib=temp, setin=aggin, setoutlib=sf32000, setout=moschls, aggby=ncescode county, agglvl=2, idlens=SumLev $3 geocode $11 AreaName $64 desedist $6 cnty desecnty $3 partflag $1, idvs=state sumlev, afact=afact, compress=yes,printids=25, report=0);