x cd /mscdc/data/georef/Tools; %let pgm=comcod94; filename pgm "&pgm..sas"; *--Read the report file from usaco94 cd-rom file with defns of metro areas (MA's) and create the georef.comcod94 and georef.metro94 datasets and the georef.msa94, georef.pmsa94 and georef.cmsa94 views. Also generate the SAS format codes (source and catalog): $metro94_ $pmsa94_ $cmsa94_ $comet94_ ---; libname georef '/mscdc/data/georef'; libname popests '/mscdc/data/popests'; filename usaco94 '/mscdc/data/georef/usmetros.usacos94.asc'; filename Smetro94 '/mscdc/sas/formats/Smetro94_.sas'; filename Spmsa94 '/mscdc/sas/formats/Spmsa94_.sas'; filename Scmsa94 '/mscdc/sas/formats/Scmsa94_.sas'; filename Scomet94 '/mscdc/sas/formats/Scomet94_.sas'; filename Sstfpcen '/mscdc/sas/formats/Sstfpcen.sas'; options nocenter; title "&pgm: Create georef datasets comcod94 and metro94"; libname user '/SAS_temp/temp.user.sdl'; /* *<====================comment out=================== data georef.metro94(label='Metro Areas (MSA, CMSA and PMSA) 94'); infile usaco94 truncover length=ll; length mcode $4 mtype $1 areaname $40 metronam $64; input mcode $1-4 @; lname=ll-20; if length(mcode)=4 & lname & verify(mcode,'0123456789') =0 then do; input @21 metronam $varying. lname; *--look at the last work of the metro name to figure type--; _ix=index(metronam,'MSA'); if _ix =0 then do; file log; put '**Metro Type not specified for ' mcode= metronam= _n_= lname= ll=; list; nbad+1; if nbad ge 20 then stop; end; else do; mtype=substr(metronam,_ix-1,1); retain sfx '( )'; drop sfx; if mtype=' ' then mtype='M'; else substr(sfx,2,1)=mtype; areaname=substr(metronam,1,_ix-1); *--truncate MSA, PMSA, CMSA-; if mtype='C' or mtype='P' then do; if length(areaname) gt 37 then areaname=substr(metronam,1,37)||sfx; else substr(areaname,_ix-1)=sfx; end; end; end; else do; input; delete; end; *<--release trailing at and go to next; keep mcode mtype areaname; run; proc print data=georef.metro94(obs=50); title2 '1st 50 Obs on georef.metro94'; run; %notify(1) proc sql; create view georef.msa94 as select * from metro94 where mtype='M'; create view georef.cmsa94 as select * from metro94 where mtype='C'; create view georef.pmsa94 as select * from metro94 where mtype='P'; quit; *genfmat(fmatname=metro94_,sasin=georef.metro94,argvars=mcode,arglen=4, labelvar=areaname,labellen=40, textfile=smetro94) ****<===this invocation commented out: we do not want to rerun it because we have done extensive post-editing including manual inclusion of the value from the $necma format====; *--and test it--; data _null_; set georef.metro94(obs=5); put mcode mcode $metro94_.; run; %genfmat(fmatname=pmsa94_,sasin=georef.pmsa94,argvars=mcode,arglen=4, labelvar=areaname,labellen=40, textfile=spmsa94) *--and test it--; data _null_; set georef.pmsa94(obs=5); put mcode mcode $pmsa94_.; run; %genfmat(fmatname=cmsa94_,sasin=georef.cmsa94,argvars=mcode,arglen=4, labelvar=areaname,labellen=40, textfile=scmsa94) *--and test it--; data _null_; set georef.cmsa94(obs=5); put mcode mcode $cmsa94_.; run; *---------Part 2: Generate georef.comet94 - county to metro 1994--; *--uses the 1994 pop estimtes file (popests.uscom94) as source to create georef.comets94 (COunty METroS 94). Note that in New England we get NECMA codes here whereas those units were not used on the previous usmetros.usacos94 file (tho the notes say they are)--; *--real quick step: create a format code to map FIPS state codes to census state codes. Since the first digit of the census code is the division it will serve as a fips state to div lookup table-; data stcodes; set stf903.usstates(keep=slvl state statece geocomp); where slvl='040' and geocomp='00'; run; %genfmat(fmatname=stfpcen,sasin=stcodes,argvars=state,arglen=2, labelvar=statece,labellen=2, textfile=Sstfpcen) *--and test it--; data _null_; set popests.uscom94; where slvl eq '040'; put state state $stfpcen. ; run; data georef.comets94(label='County Metro Links as of 6-30-94' sortedby=state county); *--length stmt here controls variable order--; length county $5 stab $2 state $2 cnty $3 msacmsa pmsa metronm $4; set popests.uscom94(keep=state--msacmsa pop90 popjl94); where slvl='050' and msacmsa ne '9999'; drop areaname cmsa2; format county $fipcnty16.; format pop90 popjl94 comma11.; stab=put(state,$fipstab.); div=put(state,$stfpcen.); if pmsa ne ' ' then metronm=pmsa; else metronm=msacmsa; format metronm $metro94_.; run; ====================end comment====================== */ proc print data=georef.comets94(obs=50); by state; id county cnty; title2 '1st 50 obs on georef.comets94'; run; *-------and now create the $comet94_ format code corresponding to this dataset. It can be used in place of $cntymet where current (July 94) metro codes are to be linked to a FIPS county code-; data cntlin; set georef.comets94; length arg $6 mcode $5 mtype $1; mcode=msacmsa; if div='1' then mtype='N'; else if pmsa ne ' ' then mtype='C'; else mtype='M'; substr(mcode,5,1)=mtype; arg=county; output; if pmsa ne ' ' then do; substr(arg,6,1)='P'; mcode=pmsa||'P'; output; end; run; %genfmat(fmatname=comet94_,sasin=cntlin,argvars=arg,arglen=6, labelvar=mcode,labellen=5, textfile=scomet94) data _null_; infile scomet94 obs=20; input; file print; title2 '1st 20 lines of $comet94_ format source'; put _infile_; run; *--test step to use the new $comet94_ format--; data _null_; length fmcode fpcode $5 arg $6; set georef.comets94(keep=county msacmsa pmsa); where county=:'17'; fmcode=put(county, $comet94_.); if pmsa ne ' ' then do; arg=county||'P'; fpcode=put(arg,$comet94_.); end; put _all_; run;