%let name=census_block_wake_county_nc; /* Set your current-working-directory (to read/write files), if you need to ... %let rc=%sysfunc(dlgcdir('c:\someplace\public_html')); */ filename odsout '.'; libname here '.'; /* Downloaded & extracted ftp://ftp2.census.gov/geo/tiger/TIGER2010BLKPOPHU/tabblock2010_37_pophu.zip proc mapimport datafile="D:\\public\census_2010\tracts\tabblock2010_37_pophu.shp" out=tabblock2010_37_pophu; id blockid10; run; */ /* libname robsdata "\\l7a695.na.sas.com\public\census_2010\tracts\"; data wake_blockmap; set robsdata.tabblock2010_37_pophu (where=(countyfp10="183")); run; proc greduce data=wake_blockmap out=wake_blockmap; id blockid10; run; data here.wake_blockmap; set wake_blockmap (where=(density<=2)); run; */ proc gproject data=here.wake_blockmap out=wake_blockmap eastlong degrees parmout=projparm; id blockid10; run; data county_outline; set mapsgfk.us_counties (where=(statecode='NC' and county=183)); run; proc gproject data=county_outline out=county_outline latlong eastlong degrees parmin=projparm parmentry=wake_blockmap; id state county; run; /* I'm using the old maps.uscity, rather than mapsgfk.uscity, because I can say "where pop>500" in the old data, but I can only say "where poptype^='under10k'" with the new gfk data. */ data cities (keep = lat long city); set maps.uscity (where=(statecode='NC' and county=183 and pop>300)); long=long*-1; run; proc gproject data=cities out=cities latlong eastlong degrees parmin=projparm parmentry=wake_blockmap; id; run; data all_plot; set county_outline (rename=(x=county_x y=county_y)) cities (rename=(x=city_x y=city_y)); run; /* Extract the population data from the map */ proc sql noprint; create table pop_data as select unique blockid10, pop10 from wake_blockmap; quit; run; proc format; value $poprang 'a' = '0' 'b' = '1-15' 'c' = '16-35' 'd' = '36-61' 'e' = '62-121' 'f' = '122-2,111' ; run; data pop_data; set pop_data; format range $poprang.; if pop10=. then range=' '; else if pop10=0 then range='a'; else if pop10<=15 then range='b'; else if pop10<=35 then range='c'; else if pop10<=61 then range='d'; else if pop10<=121 then range='e'; else if pop10<=121 then range='e'; else if pop10>=122 then range='f'; run; /* sort the data, to control order of legend */ proc sort data=pop_data out=pop_data; by range; run; /* Since sgmap doesn't support direct control of color yet, do it with an ODS style */ ods path(prepend) work.templat(update); proc template; define style colorramp; parent=styles.htmlblue; class graphcolors / 'gdata1'=cxf0edf7 'gdata2'=cxd2c5ef 'gdata3'=cxc1b1e7 'gdata4'=cxb29edf 'gdata5'=cxa38cd7 'gdata6'=cx967cd0 ; end; run; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Wake County, NC, 2010 population by census block") style=colorramp; ods graphics / noscale /* if you don't use this option, the text will be resized */ /* imagemap tipmax=2500 */ imagefmt=png imagename="&name" width=850px height=900px noborder; /* title1 color=gray33 height=20pt "Wake County, NC - census block map (unprojected)"; proc sgmap mapdata=here.wake_blockmap noautolegend; choromap / mapid=blockid10 lineattrs=(thickness=1); run; title1 color=gray33 height=20pt "Wake County, NC - census block map (projected)"; proc sgmap mapdata=wake_blockmap noautolegend; choromap / mapid=blockid10 lineattrs=(thickness=1); run; title1 color=gray33 height=20pt "Wake County, NC - 2010 Population, by census block"; proc sgmap mapdata=wake_blockmap maprespdata=pop_data noautolegend; choromap range / mapid=blockid10 id=blockid10 name='popmap' lineattrs=(thickness=0); keylegend 'popmap' / title='Population'; run; */ title1 color=gray33 height=20pt "Wake County, NC - 2010 Population, by census block"; proc sgmap mapdata=wake_blockmap maprespdata=pop_data noautolegend plotdata=all_plot; choromap range / mapid=blockid10 id=blockid10 name='popmap' lineattrs=(thickness=0); scatter x=city_x y=city_y / markerattrs=(symbol=circle size=65pt color='black') transparency=.7; text x=city_x y=city_y text=city / textattrs=(color=black size=11pt weight=bold); series x=county_x y=county_y / lineattrs=(color=gray33 thickness=1px); keylegend 'popmap' / title='Population'; run; quit; ODS HTML CLOSE; ODS LISTING;