x cd /pub/data/georef/Tools; %let pgm=princities13; filename pgm "&pgm..sas"; /*--Read the CSV file (saved from xlsx file at http://www.census.gov/population/metro/data/def.html) to create georef.princities13 with codes and names of CBSA principal cities, vintage Feb 2013. We do a lookup of the "primary county" associated with each principal city. Creates georef.princities13; J. Blodgett, OSEDA, Sept, 2014 -- */ %let year=2013; %let yr=%substr(&year,3,2); title "&pgm: Create georef.princities13"; libname georef '/pub/data/georef'; libname popests '/pub/data/popests' access=readonly; filename in "/pub/data/georef/cbsaprincities&yr..csv"; *<--saved to this file via Excel---; title "&pgm"; *---There are dozens of places that are just not being found on the ussc13 data set such as Baltimore, MD. Not sure why. So pcounty is missing for these cases in final data set.--; data plcos; set popests.ussc13; where sumlev='157'; keep state placefp county popjl&yr; run; proc sort; by state placefp popjl&yr; data plcos; set plcos; by state placefp; if last.placefp; if first.placefp then allflag=1; else allflag=0; length allflag 3; keep state placefp county allflag; run; proc print data=plcos(obs=25); title2 "plcos"; run; title2 ; proc datasets library=work nolist; modify plcos; index create sp=(state placefp); quit; data georef.princities&yr(label="Principal Cities of CBSAs as of &year"); length cbsa $5 cbsaname $96 cbsatype $5 pcname $40 state $2 placefp $5 pcounty $5 ; retain Year "&year"; *<=============================YEAR effective==============================; label PCname='Principal City Name' pcounty='PC Primary County' allflag="All PC in county flag"; infile in missover dsd firstobs=4; input cbsa cbsaname cbsatype PCname state placefp ; if cbsa=' ' then stop; *<--file has an all commas line and 3 footnotes at the end--; if state ne '72' then do; *<=============================Note - not doing PR============; 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; pcounty=" "; allflag=.; end; else pcounty=county; end; drop _: county; run; proc print data=georef.princities&yr(obs=50); by year; id cbsa; run;