BookmarkSubscribeRSS Feed
sschiro
Fluorite | Level 6

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.

1 REPLY 1
jeanleid
Fluorite | Level 6

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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 699 views
  • 0 likes
  • 2 in conversation