x cd /pub/data/georef/Tools; %let pgm=sumlevs_dataset; filename pgm "&pgm..sas"; *---Create the georef.sumlevs data set where each observation represents one value of sumlev. We also use this setup to manage the various system format codes related to sumlevs. jgb, 6-15-09. ---*; options ls=160 ps=80; %libname(georef,opts=); libname user '/SAS_temp/user'; libname sf3 '/pub/data/sf32000'; %libname(sf32000x); libname popests '/pub/data/popests' access=readonly; libname sf12000 '/pub/data/census_2000/sf12000' access=readonly; %libname(pl942000); libname acs '/pub/data/acs2007'; title 'georef.sumlevs_dataset'; ods html file="&pgm..html" style=sasweb; proc format library=library; %include '/pub/sas/formats/Ssumlev.sas'; proc format library=library cntlout=user.sumlevs(keep=start label ) ; select $sumlev ; run; proc print data=user.sumlevs (obs=50); title2 'user.sumlevs'; run cancel; data user.sumlevs2; length SumLev $3 LevelName $200; set user.sumlevs; SumLev=start; LevelName=label; drop start label; run; *-----We create the initial master data set by merging a series of sources. We look at geocodes summarized on the sf3 national data set, at the geos data set in the acs2007 series for both single year and 3-yr period ests. And we also look at the cntlout data set created above from the $sumlev format code to get basic skeleton items SumLev and LevelName. And we shall include the important sascode(sumlevs_attribs) module that defines the structure of the data set, as well as providing critical documentation within its extensive comments. ------*; data acs1geos; set acs.allgeos; by sumlev; if first.sumlev then do; geocomps='n'; nareasACS1=0; end; retain geocomps; if geocomp ne '00' then geocomps='y'; else nareasACS1+1; if last.sumlev then output; keep sumlev geoid geocode areaname geocomps nareasACS1; run; proc print data=acs1geos(obs=50); title2 'acs1geos: derived from acs2007.allgeos'; id sumlev; run cancel; data acs3geos; set acs.allgeos3yr; by sumlev; if first.sumlev then do; geocomps='n'; NareasACS3=0; end; retain geocomps; if geocomp ne '00' then geocomps='y'; else NareasACS3+1; if last.sumlev then output; keep sumlev geoid geocode areaname geocomps NareasACS3; run; proc print data=acs3geos(obs=50); title2 'acs3geos: derived from acs2007.allgeos3yr'; id sumlev; run cancel; proc sql; create table igeos as select distinct sumlev from sf32000x.moi ; create table hgeos as select distinct sumlev from sf32000x.moh ; create table sf3ageos as select distinct sumlev from sf3.mogeos; create table coestgeos as select distinct sumlev from popests.uscom08 where sumlev ne " "; create table scestgeos as select distinct sumlev from popests.ussc07; create table sf1ageos as select distinct sumlev from sf12000.mogeos; create table sf1cgeos as select distinct sumlev from sf12000.usgeos; create table pl94geos as select distinct sumlev from pl942000.mogeos; quit; data georef.sumlevs(label='Master Summary Level Data Set' index=(SumLev)); %include '/pub/sascode/sumlevs_attribs.sas'; merge user.sumlevs2(in=incodes) sf3.usgeos_sumlev_summary (keep=sumlev n geoid geocode areaname state rename=(n=nareas2k) in=insf3) sf3ageos(in=insf3a) igeos(in=ini) hgeos(in=inh) sf1ageos(in=insf1a) sf1cgeos(in=insf1c) pl94geos(in=inpl94) coestgeos(in=incoests) scestgeos(in=inscests) acs1geos(in=inacs1) acs3geos(in=inacs3); by sumlev; if insf3 then do; if state ne ' ' then if geocode='56045-' then SubStateCnty='c'; else SubStateCnty='s'; end; else do; if index(LevelName,'County') then SubStateCnty='c'; else if index(LevelName,'State') then SubStateCnty='s'; else SubStateCnty=' '; end; if indexw(LevelName,'Indian') | indexw(LevelName,'Tribal') | indexw(LevelName,'Alaska') then aianarea=1; else aianarea=0; length _lastword $40; _lastword=scan(Levelname,-1,' '); if _lastword=:'(' then Qualifier=_lastword; if index(qualifier,'/') then qualifier=scan(qualifier,1,'/'); if aianarea then IntLvl=5; else if sumlev in ('010','040','050','060','160','140','150','390','400','500','795','860') then IntLvl=1; ****Lots more to come here****; if inacs1 then UsedIn=catx(' ', UsedIn,'acs1'); if inacs3 then UsedIn=catx(' ', UsedIn,'acs3'); if insf3 then if insf3a=0 then UsedIn='sf3c'; else UsedIn="sf3"; else if insf3a then UsedIn="sf3a"; if insf1c then if insf1a then _file='sf1 '; else _file='sf1c '; else if insf1a then _file='sf1a'; if _file ne " " then UsedIn=catx(' ',UsedIn,_file); if inpl94 then UsedIn=catx(' ',UsedIn,'pl94'); if incoests then UsedIn=catx(' ',UsedIn,'coests'); if inscests then UsedIn=catx(' ',UsedIn,'scests'); if ini then ih='i'; else if inh then ih='h'; UsedIn=left(UsedIn); if index(LevelName,"New England") then do; Special_Universe="New England"; IntLvl=3; end; else if index(LevelName,"Puerto") then do; Special_Universe="PR"; IntLvl=4; end; if anyalpha(SumLev) then Source="MCDC"; else Source="Census Bureau"; Sample_Geoid=geoid; Sample_geocode=geocode; Sample_areaname=Areaname; _ndashes=count(Levelname,'-'); Nlvls=_ndashes+1; if Nlvls=1 then LowLevelCode=SumLev; keep SumLev -- Geocomps; *---so controlled by included attribs module---; run; proc print data=georef.sumlevs( drop= lowlevel: Parent: Alternate: Years: Notes Update: AltSort: Fmt:) ; id sumlev; where intlvl <= 3; title2 "Observations in georef.sumlevs"; run; ods html close;