I'm trying to control the colors on a map - plotted using proc sgmap. I keep getting an error when I try to use dattrmap to assign the colors, likely because I'm using SAS v9.4. Any suggestions on how to control the colors used in the map?
data attrmap;
input id $1 value $3-19 fillcolor $20-40;
datalines;
A Greater than 60 cx3182bd
A 31 - 60 cx6baed6
A 11 - 30 cx9ecae1
A 1 - 10 cxc6dbef
A 0 cxFFFFFF;
run;
ods graphics / border outputfmt=png;
title 'NC Counties with Cardiac Surgeries in 2022';
proc sgmap mapdata=nc maprespdata=county_pop plotdata=hospitals;* dattrmap=attrmap;
choromap group / mapid=county lineattrs=(color=blue) id=county name='counties' attrmap=A;
bubble x=long y=lat size=count / fillattrs=(color=yellow)
name='hospitals';* datalabel=county
datalabelattrs=(color=black
size=9
style=italic);
keylegend 'counties' / title='County Surgery Count';
keylegend 'hospitals' / title='Hospital';
run;
ods graphics / reset;
title;
Error messages:
5816 proc sgmap mapdata=nc maprespdata=county_pop plotdata=hospitals dattrmap=attrmap;*
--------
22
76
5816! dattrvar=A;
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DESCRIPTION, MAPDATA,
MAPRESPDATA, NOAUTOLEGEND, PLOTDATA.
ERROR 76-322: Syntax error, statement will be ignored.
5817 choromap group / mapid=county lineattrs=(color=blue) id=county name='counties' attrmap=A;
-------
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, DENSITY, DISCRETE, ID,
LEGENDLABEL, LINEATTRS, MAPID, NAME, TRANSPARENCY.
ERROR 76-322: Syntax error, statement will be ignored.
Hi,
First, when I ran a proc print of you dataset 'attrmap' the variable 'fillcolor' is only populated for the first row. Double check that this dataset looks the way you want it to.
Next, double check the syntax you are using on both the proc sgmap and choromap statements. It should look like:
proc sgmap mapdata= nc
plotdata= hospitals
maprespdata= county_pop dattrmap= attrmap ;
choromap group / mapid=county lineattrs=(color=blue) id=county name='counties' attrid= A;
run;
Maps are tricky so sometimes it helps to run each layer (choro, bubble) separately. Once you are satisfied that each layer works, then run the entire code.
Hope this helps!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.