x cd /pub/data/acs2006/Tools; %let pgm=add_geos_to_dataset; filename pgm "&pgm..sas"; /*--- AFter merging profile and basetable data, we need to add geo information so that we have an unique indentifer (esriid) 10/3/2007 - bce ---*/ *libname user '/SAS_temp/user'; libname acs2006 '/pub/data/acs2006/'; libname profiles '/pub/data/acs2006/profiles'; /* PROC DATASETS; DELETE usprofiles test profiletest basetest; * list dataset names to delete here ; RUN; */ data allgeos; set acs2006.allgeos(keep=sumlev geoid state name logrecno); length _new $ 100; *length esriid $ 7; areaname=name; if sumlev in (010, 020, 030, 040, 050, 160, 310, 400, 500, 795); MERGE_AREANAME=Upcase(compress(areaname, '/_-, ')); * do a string replace from 'MICROPOLITANSTATICALAREA" to "MSA"; _rx=rxparse("'MICROPOLITANSTATISTICALAREA' to 'MSA'"); call rxchange(_rx,1,MERGE_AREANAME, _new); call rxfree(_rx); MERGE_AREANAME=_new; _rx=rxparse("'METROPOLITANSTATISTICALAREA' to 'MSA'"); call rxchange(_rx,1,MERGE_AREANAME, _new); call rxfree(_rx); MERGE_AREANAME=_new; _rx=rxparse("'URBANIZEDAREA' to 'UA'"); call rxchange(_rx,1,MERGE_AREANAME, _new); call rxfree(_rx); MERGE_AREANAME=_new; drop _:; drop name; run; data uscensusprofiles_wo_geos; set profiles.uscensusprofiles_wo_geos; *length areaname $ 100; * add on MSA to the areaname below, it was left off; if areaname='New York-Northern New Jersey-Long Island, NY-NJ-PA' then areaname='New York-Northern New Jersey-Long Island, NY-NJ-PA MSA'; * remove (109th... off from the name since length of areaname is random; if sumlev=500 then do; _loc=index(areaname, "(1"); if _loc > 0 then areaname=substr(areaname, 1, _loc-1) || "(109th Congress)"; else if areaname='Delegate District (at Large), District of Columbia' then areaname='Delegate District (at Large), District of Columbia (109th Congress)'; end; MERGE_AREANAME=Upcase(compress(areaname, '/_-, ')); drop _:; drop d60 d66 moe60 moe66; * these are always blank; run; proc sort data=uscensusprofiles_wo_geos; by sumlev MERGE_AREANAME; run; proc sort data=allgeos; by sumlev MERGE_AREANAME; run; data profiles.uscensusprofiles; merge allgeos(in=y) uscensusprofiles_wo_geos(in=x); by sumlev MERGE_AREANAME; if x=1 and y=1; * only want to keep data in acs2006data_without_geos; drop MERGE_AREANAME name sumlevmoe areanamemoe; run;