BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JW_Hyde
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Please show us your code if you want a usable code answer 🙂

JW_Hyde
Obsidian | Level 7
ods html close;
ods listing close;
ods graphics / imagemap=on imagename="&imgcht1"
height=750px width=1200px
tipmax=1600 antialiasmax=1600;

ods html path=grf1 body="&tagcht1" ;

proc sgplot data=acctout;
yaxis
labelattrs=(size=8 color=black)
LABEL= '# of Requests'
refticks
min=0
valueattrs=(size=8 color=black )
;
xaxis
fitpolicy= rotatethin
labelattrs=(size=8 color=black)
;
title1 h=1.5 c=black j=c f=swissb
'PROD';
title2 h=1.0 c=gray j=c f=swissb
"Reported Day = &EDTT";
title3 h=1.0 c=gray j=c f=swissb
"By appname";

vbar date/response=req
group=appname dataskin=gloss;

run ;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
JW_Hyde
Obsidian | Level 7
I would do that but I have a couple dozen categories and maybe more on the way.
That's a bit of a maintenance headache.
PeterClemmensen
Tourmaline | Level 20

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

 

 

SGPlot25.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

And here it is without the red color

 

 

SGPlot24.png

JW_Hyde
Obsidian | Level 7

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.

ballardw
Super User

@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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 1394 views
  • 1 like
  • 4 in conversation