x cd /pub/data/mable2k/Tools; %let pgm=usschoolcodes; filename pgm "&pgm..sas"; *---Analyze the mable2k database to come up with mable2k.usschoolcodes with a variety of derived codes for all the school districts in the US. John Blodgett, OSEDA (per request from W. Elder, OSEDA), April, 2003. Rerunning 5-29-03 to add district name. ---; libname mable2k '/pub/data/mable2k'; libname user '/SAS_temp/user'; title 'Geographic Characteristics of School Districts as of the 2000 Census (with Some 1990)'; *macro doit(state,stab); %let state=10; %let stab=de; data codes; set %macro doit(state,stab); mable2k.&stab.v(keep=county Cnty CntySC msacmsa sdelm sdsec sduni ur state pop2k tract block) %mend doit; %dostates (n=51) open=defer; length School $5 SchlName $7 SchlType $1 Nschl 3 Metro $1; *---nschl is assigned value of 1, 2 or 3 as we output possibly multiple district types for an obs. If only 1 type of district is found nschl is always 1. But when we find a second type for the same block we get nschl=2. Etc. ---; array _sd (3) sdelm sdsec sduni; retain _sdtype 'esu'; if msacmsa='9999' then Metro='n'; else metro='y'; *<---metro area flag--; Nschl=0; do _i=1 to 3; School=_sd(_i); if School not in ('99999',' ') then do; Nschl+1; SchlType=substr(_sdtype,_i,1); SchlName=state||School; output; end; end; if Nschl=0 then do; file print; put 'No school codes for this block: ' state= county= tract= block=; _noschool+1; if _noschool gt 1000 then abort abend; delete; end; keep state SchlType School SchlName UR Cnty CntySC UR Metro Pop2k Nschl County; format SchlName $leaname.; run; proc sort data=codes out=codes2; by State SchlType School Cnty ; run; data mable2k.&pgm(label='Miscellaneous School District Codes'); set codes2; by State SchlType School Cnty; retain; if first.School then do; TotPop2k=0; UrbanPop2k=0; MetroPop2k=0; NCounties=0; Overlap=0; CntySC_Lo=cntysc; CntySC_Hi=cntysc; end; if first.cnty then do; Ncounties+1; if CntySC > CntySC_Hi then CntySC_Hi=CntySC; if CntySC < CntySC_Lo then CntySC_Lo=CntySC; end; if UR='U' then UrbanPop2k+ pop2k; if Metro='y' then MetroPop2k+ pop2k; if Nschl gt 1 then Overlap=pop2k; TotPop2k + pop2k; drop CntySC Metro cnty Nschl pop2k ur _thresh ; if last.school then do; _thresh=.75*TotPop2k; if UrbanPop2k ge _thresh then Urban2k=1; else Urban2k=0; if MetroPop2k ge _thresh then Metro2k=1; else Metro2k=0; output; end; format county $county12.; run; proc print data=mable2k.&pgm (obs=50); by state schltype; id school; title "mable2k.&pgm"; run;