I dont want to use the color red from this random list of colors in the plot. How do I omit the red color from the plot?
In general, I am a believer in controlling the colors yourself, rather than let SAS do it for you. Thus, you could use the STYLEATTRS command in PROC SGPLOT, specifying the DATACOLORS= option and then you get whatever colors you want.
Please show us your code if you want a usable code answer 🙂
In general, I am a believer in controlling the colors yourself, rather than let SAS do it for you. Thus, you could use the STYLEATTRS command in PROC SGPLOT, specifying the DATACOLORS= option and then you get whatever colors you want.
I stole some code from the blog post What colors does PROC SGPLOT use for markers? that might help you.
This lets you control the colors in the Styleattrs Statement dynamically. Here, I drag the red color out of the picture
libname temp "C:/temp";
proc template;
source styles.statistical / file='temp.tmp'; /* write template to text file */
quit;
data Colors;
keep Num Name Color R G B;
length Name Color $8;
infile 'temp.tmp'; /* read from text file */
input;
/* example string: 'gcdata1' = cx445694 */
k = find(_infile_,'gcdata','i'); /* if k=0 then string not found */
if k > 0 then do; /* Found line that contains 'gcdata' */
s = substr(_infile_, k); /* substring from 'gcdata' to end of line */
j = index(s, "'"); /* index of closing quote */
Name = substr(s, 1, j-1); /* keyword */
if j = 7 then Num = 0; /* string is 'gcdata' */
else /* extract number 1, 2, ... for strings */
Num = inputn(substr(s, 7, j-7), "best2."); /* gcdata1, gcdata2,... */
j = index(s, "="); /* index of equal sign */
Color = compress(substr(s, j+1)); /* color value for keyword */
R = inputn(substr(Color, 3, 2), "HEX2."); /* convert hex to RGB */
G = inputn(substr(Color, 5, 2), "HEX2.");
B = inputn(substr(Color, 7, 2), "HEX2.");
end;
if k > 0;
run;
proc sql noprint;
select Color into :colorlist separated by ' '
from Colors where Color ne 'cxA23A2E';
quit;
%put &colorlist.;
data A;
do Color = 1 to 20;
x = Color; y = Color; output;
end;
run;
proc sgplot data=A;
*styleattrs Datacolors = (&colorlist.);
vbar y / group=Color;
run;
Here is the result without the Styleattrs Statement
And here it is without the red color
In the end this was the solution I chose. I had to define a color list for 3 dozen colors but I did get something that was more presentable. Just make sure that the color BLUE is not the first color in your list.
Thanks all.
@JW_Hyde wrote:
I dont want to use the color red from this random list of colors in the plot. How do I omit the red color from the plot?
Unless you are writing code to explicitly make a random set of colors SAS does not use a "random list of colors". The first color used for the first graph element displayed will be the color defined in the current style for graphcolor1 and/contrast, the second item with graphcolor2 and so on through 12 with typical SAS defined styles. Then an algorithm creates others or reuses depending on options.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.