I am trying to create a plot using sgplot and scatter that will color code data points based on the value of an endogenous variable. I used to do this through SAS Insight, but that is gone. I thought I could do it through attribute maps, but I am getting errors. In the code below I am plotting 6 values (x,y pairs) color coding by the value of x. Is there a better/easier way to do this. Please excuse the rough state of the code.
SAS 9.4 64 bit TS1M1
Windows 7 under Mac Book Pro (Yosemite 10.10.3): Parallels 10.2.1
Thanks for any help on this.
data attrib (drop=x red green blue) ;
format red green blue hex2. ;
length linecolor $8 fillcolor $8;
input @1 x @1 value$ y;
ID = 'Test';
red = int((x/48)*255);
green = 0;
blue=255 - red;
fillcolor= cats('CX',put(red, hex2.),put(green, hex2.),put(blue, hex2.));
data trial ;
input x y;
proc sgplot data=trial DATTRMAP=attrib;
scatter x=x y=y/FILLEDOUTLINEDMARKERS markerattrs=(symbol=circlefilled size=10) group=x ATTRID=Test;
I managed to get this to work by:
1) Removing the FILLEDOUTLINEDMARKERS option
2) Changing the attribute variable name "fillcolor" to "MarkerColor".
Is there a list of keyword for attribute map variables?
Also, what if I still wanted outlined markers?
There is a section in the ODS Graphics doc for the SG Procedures that discusses Attribute Maps and shows the list of reserved variable names:
SAS(R) 9.4 ODS Graphics: Procedures Guide, Fourth Edition (the specific link with reserved variables)
SAS(R) 9.4 ODS Graphics: Procedures Guide, Fourth Edition (the top link that shows all the sections)
What you need is a color response based on a variable.
COLORRESPONSE is supported for both SCATTER and BUBBLE starting from SAS 9.4(TS1M2). You are using TS1M1, so that option is not available. However, these options are available in GTL in TS1M1.
An easy way to get started would be to run the SGPLOT procedure as you have, and set TMPLOUT="FileName.sas" SGPLOT will write the generated GTL template program to this file name. Template name will be "SGPLOT". Go to the ScatterPlot statement as add the option MARKERCOLORGRADIENT=variable. You can also use the COLORMODEL option to get the colors you want, or use DISCERTEATTRMAP to get full control on colors and values.
You will need to use the following statement to run the graph from template.
proc sgrender data=foo template=sgplot;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.