x cd /pub/data/georef/Tools; %let pgm=nectas05; filename pgm "&pgm..sas"; *--create data sets with info regarding New England City and Town Areas and NECTA divisions. jgb, Feb. 2007 --*; %let setsfx=; *<---------use 2-digit lastest year as value while testing. Set to null for final run. Allows us to generate new versions of these datasets without initially replacing the old ones.----------; %let nectayr=2005; %let month=Dec; *---close enough--; %let popestyr=05; *<--- we get population estiamtes and msacmsa/pmsa codes from popests.uscom&popestyr --; filename in '../nectadefs.jan2006.txt'; *<--downloaded from http://www.census.gov/population/estimates/metro_general/List7.txt, 2-13-07 ---; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; libname user '/SAS_temp/userb'; * options nofmterr; title "&pgm: Create georef Data Sets Related to NECTAs and NECTA Divisions &month, &nectayr"; data nectas( keep=SumLev necta nectatype AreaName Year) nectadivs(keep=SumLev necta nectatype nectaname NectaDiv AreaName Year) georef.nectamcds&setsfx(keep=SumLev stab state cnty county fipco mcd MCDname necta nectatype nectaname nectadiv Year); infile in end=last truncover firstobs=16 ; length SumLev $3 Necta $5 NectaDiv $5 county $5 MCD $5 Level $10 AreaName $80 nectaname $5 MCDname $10; length fipco nectatype $5 State Stab $2 cnty $3; retain Year "&nectayr"; retain NectaName; input necta $5. @; if necta='File ' then stop; if length(necta)=5 and verify(necta,'0123456789')=0; *---look for lines with 5-digit numerics in cols 1-5--; input NectaDiv $9-13 county $17-21 MCD $22-26 AreaName $25-99 ; if length(mcd)=5 then level='Component'; else if length(NectaDiv)=5 then level='Division'; else level='necta'; select (Level); when ('necta') do; SumLev='350'; NectaName=necta; format nectaname $necta.; *** =Areaname; if index(areaname,'Metropolitan ') then nectatype='Metro'; else if index(areaname,'Micropolitan ') then nectatype='Micro'; else do; nectatype='?????'; put _all_; end; retain nectatype; output nectas; end; when ('Division') do; SumLev='355'; ***nectaname=necta; output nectadivs; end; when ('Component') do; SumLev='358'; fipco=county; format county $county.; State=substr(county,1,2); Stab=put(state,$fipstab.); cnty=substr(county,3,3); MCDname=fipco||MCD; format MCDname $cousub.; output georef.nectamcds&setsfx; end; otherwise do; put 'nectatype not recognized: ' level _n_= / _infile_; delete; end; end; label necta='New England city & town Area' mcd='Minor Civil Div (town)'; run; proc sort data=georef.nectamcds&setsfx; by county mcd; run; proc sort data=nectadivs out=georef.nectadivs&setsfx(index=(nectadiv) label="Necta Divisions as of &month, &nectayr"); by necta nectadiv; run; proc sort data=nectas out=georef.nectas&setsfx(index=(necta) label="Core Based Stat Areas &month, &nectayr"); by necta; run; *----Generate $necta, and $nectadiv permanent format codes----; filename text '/pub/sas/formats/Snecta.sas'; filename text2 '/pub/sas/formats/Snectadv.sas'; %genfmat(setin=georef.nectas&setsfx,argvars=necta,labelvar=areaname,labellen=75,arglen=5,fmatname=necta,savedoc=0); %genfmat(setin=georef.nectadivs&setsfx,argvars=nectadiv,arglen=5,labelvar=areaname,labellen=75,fmatname=nectadv, textfile=text2,savedoc=0); *----These formats will permit doing format-table-lookups of county/mcd combinations to get necta and nectadiv codes--; filename text3 '/pub/sas/formats/Smcdnect.sas'; filename text4 '/pub/sas/formats/Smcdnecd.sas'; %genfmat(setin=georef.nectamcds&setsfx,argvars=fipco mcd,labelvar=necta,labellen=5,arglen=10, fmatname=mcdnect,textfile=text3,savedoc=0); %genfmat(setin=georef.nectamcds&setsfx,argvars=fipco mcd,labelvar=nectadiv,labellen=5,arglen=10, fmatname=mcdnecd,textfile=text4,savedoc=0); data testfmts; set georef.nectamcds(keep=necta nectadiv mcd state fipco county where=(nectadiv ne ' ') obs=25); length _arg $10; _arg=fipco||mcd; length nectaname nectadivname $75 necta_lookup nectadiv_lookup $5; nectaname=put(necta,$necta.); nectadivname=put(nectadiv,$nectadv.); necta_lookup=put(_arg,$mcdnect.); nectadiv_lookup=put(_arg,$mcdnecd.); put / _all_; run;