x cd /pub/data/georef; %let pgm=genlocs; filename pgm "&pgm..sas"; *--Generate sas data sets and format codes: georef.moblloc georef.mobgloc and georef.moblloc with 3 corr. format codes. The Location variable we calculate is the name of the geographic area most associated with the geographic entity. jgb, 9.12.01--; libname sf12000 '/pub/data/census_2000/sf12000' access=readonly; libname georef '/pub/data/georef'; libname user '/tmp/storage/john'; filename blfmt '/pub/sas/formats/Smoblloc.sas'; filename bgfmt '/pub/sas/formats/Smobgloc.sas'; filename trfmt '/pub/sas/formats/Smotrloc.sas'; data georef.moblloc ; set sf12000.mogeos(where=(sumlev='101') keep=sumlev county tract bg block placefp cousubfp pop100); if placefp='99999' then loc='t'||cousubfp; else loc='p'||placefp; *--place of unincorporated township--; length location $40; if placefp='99999' then location='Uninc. '||put(cousubfp,$momcd.); else do; location=put(placefp,$mofplac.); _l=length ( scan(location,-1,' ')); *--get length of last word; if length(location) > 5 then location=substr(location,1, length(location)-_l); drop _l; end; drop placefp cousubfp sumlev; run; proc sort data=georef.moblloc; by county tract block; run; proc sort data=georef.moblloc(drop=block) out=mobgloc; by county tract bg loc; run; %corrwt(setin=mobgloc, setout=bg2loc, g1=county tract bg, g2=loc, weight=pop100,keepwt=1) proc sort data=bg2loc; by county tract bg pop100; run; data georef.mobgloc(label='MO BGs and Locations'); set bg2loc; by county tract bg; if last.bg; *<---the largest bg---; length location $40; if loc=:'t' then do; cousubfp=substr(loc,2); location='Uninc. '||put(cousubfp,$momcd.); end; else do; placefp=substr(loc,2); location=put(placefp,$mofplac.); *--truncate the last word, be it city, village, ... --; _l=length ( scan(location,-1,' ')); *--get length of last word; if length(location) > 5 then location=substr(location,1, length(location)-_l); drop _l; end; if afact < .5 then location=trim(location)||' (et. al)'; else if afact < 1 then location=trim(location)|| ' (mostly)'; *--the trailing asterkisk notation indicates the degree to which the geographic entity is within the location area; drop cousubfp placefp; format afact 5.3; run; *----------Now do it for census tracts-------------*; proc sort data=georef.moblloc(drop=block) out=motrloc; by county tract loc; run; %corrwt(setin=motrloc, setout=tr2loc, g1=county tract , g2=loc, weight=pop100,keepwt=1) proc sort data=tr2loc; by county tract pop100; run; data georef.motrloc(label='MO Tracts and Locations'); set bg2loc; by county tract ; if last.tract; *<---the largest tract---; length location $40; if loc=:'t' then do; cousubfp=substr(loc,2); location='Uninc. '||put(cousubfp,$momcd.); end; else do; placefp=substr(loc,2); location=put(placefp,$mofplac.); *--truncate the last word, be it city, village, ... --; _l=length ( scan(location,-1,' ')); *--get length of last word; if length(location) > 5 then location=substr(location,1, length(location)-_l); drop _l; end; if afact < .5 then location=trim(location)||' (et. al)'; else if afact < 1 then location=trim(location)|| ' (mostly)'; *--the trailing asterkisk notation indicates the degree to which the geographic entity is within the location area; drop cousubfp placefp; format afact 5.3; run; proc freq data=georef.motrloc; table location; run; *-----------------Now generate the 3 SAS format tables. 1 for blocks, 1 for bgs and 1 for tracts------------; %genfmat(setin=georef.moblloc,fmatname=moblloc,argvars=county tract block,labelvar=location,arglen=16,labellen=40, intrvls=1,textfile=blfmt,procstmt=0,runproc=0) run; %genfmat(setin=georef.mobgloc,fmatname=mobgloc,argvars=county tract bg,labelvar=location,arglen=13,labellen=40, intrvls=1,textfile=bgfmt,procstmt=0,runproc=0) %genfmat(setin=georef.motrloc,fmatname=motrloc,argvars=county tract,labelvar=location,arglen=12,labellen=40, intrvls=0,textfile=trfmt,procstmt=0,runproc=0) proc format library=library; %include blfmt; %include bgfmt; %include trfmt; run;