x cd /pub/data/corrlst/Tools; %let pgm=hud_zipequivs; filename pgm "&pgm..sas"; *---Process the latest 3 ZIP equivalency files (to county, to CBSA and to tract) as downloaded from their web page http://www.huduser.org/portal/datasets/usps_crosswalk.html jgb, Jan, 2011 ---*; filename cbsain '/pub/data/corrlst/ZIP_CBSA_092010.dbf'; filename cntyin '/pub/data/corrlst/ZIP_COUNTY_092010.dbf'; filename trctin '/pub/data/corrlst/ZIP_TRACT_092010.dbf'; libname user '/SAS_temp/user'; libname corrlst '/pub/data/corrlst'; libname georef '/pub/data/georef' access=readonly; %let cbsayear=2009; *<====; options compress=yes; /* ========================begin comment==================================== proc dbf db4=cbsain out=user.cbsas; proc sort data=cbsas; by cbsa; run; proc contents; run; proc dbf db4=cntyin out=user.counties; proc contents; run; proc dbf db4=trctin out=user.tracts; proc contents; run; ==========================end comment====================================== */ proc sql; create table cbsadivs as select distinct cbsa, cbsatype, metrodiv from georef.cbsacos order by cbsa, metrodiv; quit; data cbsadiv2; set cbsadivs; if metrodiv ne ' ' then do; length cbsaname $80; containedIn=cbsa; cbsatype='mtdiv'; cbsa=metrodiv; cbsaname=put(metrodiv,$metrodiv.); end; else cbsaname=put(cbsa,$cbsa.); rename cbsatype=mtype; run; proc sort; by cbsa; run; *---OK, we have our raw data in SAS data sets. We want to merge the 3 into a single data set with 3 kinds of geography. They'll have common geographic and XXX_ratio variables. ---; %let hudname=hud_zipmetro092010; data corrlst.&hudname (label='HUD ZIP to CBSA/Metro Div as of Sept 2010') hudonlycbsas(keep=metro metroname); length ZIP $5 Metro $5; label Metro='CBSA/Metro Division'; retain CBSAYear "&cbsayear"; merge cbsadiv2 (in=incbsas) cbsas(in=inhud); by cbsa; if not (incbsas and inhud) and first.cbsa then do; if not inhud then _nohud+1; else do; _nocbsas+1; cbsaname=cbsa; output hudonlycbsas; end; _nbad+1; if _nbad le 30 or not inhud then put _all_; ***else abort abend; drop _: ; end; Metro=cbsa; if mtype='mtdiv' then do; MetroDiv=cbsa; cbsa=containedIn; end; rename cbsaname = MetroName; if inhud then output corrlst.&hudname; run; proc print data=hudonlycbsas; title2 'CBSA Codes Found In HUD but Not on Our georef Dataset'; run; proc print data=corrlst.&hudname (obs=50); title2 "corrlst.&hudname"; run; proc freq data=corrlst.&hudname; table mtype; run;