x cd /mscdc/data/georef/Tools; %let pgm=comcod98; filename pgm "&pgm..sas"; *--Modeled more or less after the comco948 setup. But the source files are different (txt files downloaded from the Bureaus population/estimates/metros pages) and instead of generating sas format codes we merely look for and flag mods that we will apply manually to "fix" obsolete entries. JGB, 3-99. USING 6-30-98 metro area definitions --*; *--we ran sas steps with expandtabs option on orginal txt files in order to create these 2 "expanded" files with tabs replaced by appopritate number of blanks in the records--*; filename m_in '/mscdc/data/georef/98mfips.expanded.txt'; *--msa/cmsa/pmsa data--; filename n_in '/mscdc/data/georef/98nfips.expanded.txt'; *--necma data--; libname user '/tmp/storage/user'; libname georef '/mscdc/data/georef'; libname popests '/mscdc/data/popests'; options nocenter; title "&pgm: Create Datasets georef.comcod98 and georef.metro98"; /* *<=======================comment out====================================== data georef.metro98(label='Metro Areas (MSA, CMSA and PMSA) 98' keep=msacmsa pmsa necma mtype metronam) georef.comcod98(label='Cnty to Metro Area ref as of 6-30-98' drop=metronam towncode townname) georef.netown98(label='New England town to MA, 6-30-98' drop=msacmsa pmsa cmsa2 metronam cntyname); length msacmsa $4 mtype $1 cntyname townname metronam $58; do until(lastmet); infile m_in end=lastmet expandtabs truncover length=ll; if ll=106 then list; ***just curious--; input msacmsa $1-4 @; _nline+1; if msacmsa='1-4' then leave; *--signals beginning of the end on this file; if ll lt 49 then do; input; continue; end; *--must have a name field; if length(msacmsa) ne 4 or verify(msacmsa,'0123456789') then do; input;continue; end; input pmsa $9-12 cmsa2 $17-18 state $25-26 cnty $27-29 ccflag $33 towncode $41-45 _title $49-106; length county $5 div $1 stab $2; if state ne lag(state) and state ne ' ' then do; stab=put(state,$fipstab.); div=put(state,$stdivr1.); end; if cnty ne ' ' then county=state||cnty; else county=' '; *--throw away county header lines in New England--; if div='1' and towncode=' ' then continue; *---process town level records in NE---*; if towncode ne ' ' then do; townname=_title; output georef.netown98; end; else if county=' ' then do; *--its a metro area header record--; if pmsa ne ' ' then mtype='P'; else if cmsa2 ne ' ' then mtype='C'; else mtype='M'; metronam=_title; output georef.metro98; end; else do; *--process a county level record outside NE--*; cntyname=_title; output georef.comcod98; end; end; *--do until loop to read the 98mfips.txt file--*; put /'*****MSA File Processing Complete -- Begin Processing New England NECMA ' 'file**** '; mtype='N'; div='1'; pmsa=' '; cmsa2=' '; do until(lastnec); infile n_in end=lastnec expandtabs truncover length=ll; input msacmsa $1-4 @; _nline+1; if msacmsa='1-4' then leave; *--signals beginning of the end on this file; if ll lt 49 then do; input; continue; end; *--must have a name field; if length(msacmsa) ne 4 or verify(msacmsa,'0123456789') then do; input; continue;end; necma=msacmsa; *--store the same code in two variables--; input state $6-7 cnty $9-11 _title $16-73; length county $5 div $1 stab $2; if state ne lag(state) and state ne ' ' then do; stab=put(state,$fipstab.); end; if cnty ne ' ' then county=state||cnty; else county=' '; if county=' ' then do; metronam=_title; output georef.metro98; end; else do; cntyname=_title; output georef.comcod98; end; end; *--do until lastnec loop to read necma file--*; stop; *--we are out of data--; drop _title _nline; run; proc sort data=georef.comcod98; by state county; run; proc sort data=georef.netown98; by state county towncode; run; proc print data=georef.metro98(obs=50); title2 '1st 50 Obs on georef.metro98'; run; proc print data=georef.comcod98(obs=150); title2 'First 150 obs on georef.comcod98'; by state stab; id cnty county; run; proc print data=georef.netown98(obs=100); title2 'first 100 Obs on georef.netown98'; by state stab; id county towncode; run; %notify(1) proc sql; create view georef.msa98 as select * from metro98 where mtype='M'; create view georef.cmsa98 as select * from metro98 where mtype='C'; create view georef.pmsa98 as select * from metro98 where mtype='P'; create view georef.necma98 as select * from metro98 where mtype='N'; quit; ==================================end comment======================== */ data oldmnams; set georef.metro98; length mname1 mname2 $64; if mtype='M' then mname1=trim( put(msacmsa,$metro.) )||' MSA'; else if mtype='C' then mname1=put(msacmsa,$metro.); else if mtype='N' then mname1=put(necma,$metro.); else if mtype='P' then mname1=put(pmsa,$metro.); if mtype ne 'M' and length(mname1) gt 4 then mname1=substr(mname1,1, length(mname1)-4); select (mtype); when('M') mname1=mname1; when('C') mname1=trim(mname1)||' CMSA'; when('P') mname1=trim(mname1)||' PMSA'; when('N') mname1=trim(mname1)||' NECMA'; end; if upcase(metronam) ne upcase(mname1) then case=1; if mtype='M' then mname2=mname1; else if mtype='C' then mname2=put(msacmsa,$cmsa.); else if mtype='N' then mname2=put(necma,$necma.); else if mtype='P' then mname1=put(pmsa,$pmsa.); if mtype ne 'M' and length(mname2) gt 4 then mname2=substr(mname2,1, length(mname2)-4); select (mtype); when('C') mname2=trim(mname2)||' CMSA'; when('P') mname2=trim(mname2)||' PMSA'; when('N') mname2=trim(mname2)||' NECMA'; when('M') mname2=mname1; end; if upcase(metronam) ne upcase(mname2) then case=case+2; if case; keep msacmsa necma pmsa mtype metronam mname1 mname2; label metronam='Preferred Current Name' mname1='Name using $metro format' mname2='Name Using $CMSA, $PMSA or $NECMA format'; run; proc print data=oldmnams(obs=200); title2 'Obsolete Metro Names - Each Entry Requires Edit of SAS Format ' 'Entry'; run;