x cd /pub/data/georef/Tools; %let pgm=cbsas_princities; filename pgm "&pgm..sas"; /* --See princities13.sas for current version of setup using later data -- */ /*--Read the text file from the Bureau defining principal cities for CBSAs. As of June, 2003. We do a lookup of the "primary county" associated with each principal city. Creates georef.cbsaprincities ; J. Blodgett, OSEDA, June, 2003 Rerun Oct. 2004 to read the new cities as of December, 2003. Has to be run AFTER the cbsas03d.sas setup which regenerated the georef.cbsas dataset, which this setup then reads. ============================ -- */ title "&pgm: Create georef.cbsacities"; %let year=2003; libname georef '/pub/data/georef'; libname corrlst '/pub/data/corrlst' access=readonly; filename in "/pub/data/georef/cbsas&year.dec.princities.txt"; *<===note the "dec" here!!!!==; data plcos; set corrlst.usplco2k; by state placefp; if first.placefp; keep state placefp county afact; run; proc datasets library=work nolist; modify plcos; index create sp=(state placefp); quit; data cbsaprincities; ; length cbsa $5 pcname $40 pcstate $2 pcplacefp $5 pccounty $5 ; retain Year "&year"; *<=============================YEAR effective==============================; label pcstate='Principal City State' pcplacefp='Principal City FIPS code' pcname='Principal City Name' pccounty='Principal City Primary County' pcname='Princiapl city name'; infile in missover firstobs=9; input cbsa $5. pcname $12-80 pcstate $82-83 pcplacefp $87-91; if length(pcstate)=2 and verify(pcstate,'1234567890')=0; *--good way to pick out the place code lines from the report file--; if pcstate ne '72' then do; *<=============================Note - not doing PR============; state=pcstate; placefp=pcplacefp; drop state placefp; set work.plcos key=sp; if _iorc_ then do; put '***Place not found on plcos*** ' state= placefp=; _nbad+1; if _nbad ge 100 then abort abend; pccounty=" "; end; else pccounty=county; drop county; end; drop _: ; run; proc sort; by cbsa; run; data georef.cbsaprincities(label="Principal cities of Core Based Statistical Areas as of &year (December)" index=(cbsa)); merge georef.cbsas(rename=(areaname=cbsaname) drop=year in=in1 ) cbsaprincities(in=in2); by cbsa; length pcrank 3; lable pcrank='Principal city size rank'; pccntyname=pccounty; format pccntyname $county.; label pccntyname='Principal city primary county name'; label afact='Portion of PC city in PC county'; if not (in1 and in2) then do; put _all_ /; end; if first.cbsa then pcrank=1; else pcrank+1; run; proc print data=georef.cbsaprincities(obs=50); by year; id cbsa; run;