In my previous post SAS Discrete Attribute Map In PROC SGPLOT, I demonstrate how to use discrete attribute maps to link specific variable values with specific visual attributes in PROC SGPLOT. However, the discrete version is not the only map in town. The Range Attribute Map associates ranges of variable values with visual aspects in a graph procedure. In this post, I briefly present the range attribute map and a small example of how to set up the attribute data set and use it in a graph procedure.

The Range Attribute Map Data Set

Range Attribute Map Example Code SAS PROC SGPLOT GraphThe Range Attribute Map data set is set up quite similar to the discrete case. There are two required variables. ID and MIN. The ID variable defines the name of the particular map for later use in a graph procedure. As in the discrete case, you can define several maps in one data set. The MIN variable defines the minimum of the range for the variable value of interest. Usually, you will also define a MAX variable, though it is not required. Next, you specify the visual features you want to control with the map. You can see the controllable features at the SAS Documentation.

In this example, I want to draw a Scatter Plot of the Sepal Length vs Sepal Width in the SASHELP.IRIS data set. I want to highlight three different ranges in Sepal Length. Up until 50mm, between 50 and 60 mm and from 60 mm and up. This is a job well suited for the range map. I specify a data set with three observations. In the first observation, I set the lower bound for the range to _MIN_ and MAX to 50 indicating that up until 50mm, I want to color the markers green. I follow the same logic in the other observations. Be aware that since we specify _MIN_ and _MAX_ values in the MIN and MAX variables, these variables are bound to be character. Even though they represent bounds on numeric values.

data MyAttrmap;
length ID $4 min $8 max $8 color $6 altcolor $6;
input ID min$ max$ color altcolor$;
datalines;
MyID _min_ 50    Green Green
MyID 50    60    Gold  Gold
MyID 60    _max_ Red   Red
;
run;

Draw Scatter Plot in SAS With PROC SGPLOT

Next, I draw the scatter plot with PROC SGPLOT. I specify the MyAttrmap in the RATTRMAP= option in the procedure statement. Be aware that this is different from the DATTRMAP= Option for the discrete attribute map, even though it is just one letter. Then, I specify the MyID value in the RATTRID= Option in the Scatter Statement. Furthermore, I specify the SepalLength variable in the COLORRESPONSE= Option. This tells SAS that we want to associate ranges of values in the SepalLength variable with the visual features specified in the MyID attribute map.

title "Iris Scatter Plot With Range Attribute Map";
proc sgplot data=sashelp.iris rattrmap=MyAttrmap;
   scatter x=SepalWidth y=SepalLength / colorresponse=SepalLength rattrid=MyID markerattrs=(symbol=CircleFilled);
   yaxis display=(nolabel novalues noticks);
run;
title;

You can see the scatter plot to the right.

Summary

The post demonstrated how to associate ranges of values with specific visual attributes in SAS graphs. The attribute map concepts can be a bit overwhelming at first, but when you get the grasp of it, they are very powerful.

For more examples, see Using Range Attribute Maps and Attributes Map – 3 Range Attribute Map.

You can download the entire program from this post here.