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

I use Gplot to overlay 18-20 graphs in the same screen and would like different colors for each of them.

For the symbol statement I use repeat=20 without specifying colors,so the charts are created but the colors are repeated after the 12th graph, seems like the automatically selected colors are only 12, the 13th one is the same as the 1st.

 

What can I do to force SAS to automatically select different colors for each of the 20 graphs? I know I can manually specify 20 colors with 20 symbol statements but I'd rather avoid that.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Indeed, it seems that the limitation to 12 colors is imposed by ODS styles (as @ballardw has pointed out in the other thread). This could be avoided by switching the GSTYLE system option off: options nogstyle;

 

Now, SAS would cycle through the default color list of the device used (excluding WHITE, the background color). The number of colors in this list (at least for the device WIN) has been increased to 38 since SAS 9.2, hence would be sufficient for your 20 graphs. However, the NOGSTYLE system option has side effects (e.g. on fonts) which may or may not be acceptable to you.

 

Alternatively, you could specify a list of (at least) 20 colors in the COLORS= option of the GOPTIONS statement (no need for multiple SYMBOL statements then). As a generic list to start with you could simply copy the color list from the device entry and then edit the list as you like (e.g. delete colors that are hardly visible or too similar to others etc.). I did this in the following code example, based on the default color list of the device WIN (obtained by double-clicking entry WIN in the contents of 'Sashelp.Devices' in the CATALOG window):

 

goptions reset=all;

data test;
array y[20];
do x=1 to 3;
  do i=1 to dim(y);
    y[i]=i;
  end;
  output;
end;
run;

symbol v=dot i=join;

goptions colors=(BLACK   RED    GREEN  BLUE    CYAN
                 MAGENTA GRAY   PINK   ORANGE  BROWN
                 LIME    PERU   GOLD   HOTPINK INDIGO
                 KHAKI   PURPLE SILVER SKYBLUE TOMATO);

proc gplot data=test;
   plot (y:)*x / overlay;
run;
quit;

 

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Indeed, it seems that the limitation to 12 colors is imposed by ODS styles (as @ballardw has pointed out in the other thread). This could be avoided by switching the GSTYLE system option off: options nogstyle;

 

Now, SAS would cycle through the default color list of the device used (excluding WHITE, the background color). The number of colors in this list (at least for the device WIN) has been increased to 38 since SAS 9.2, hence would be sufficient for your 20 graphs. However, the NOGSTYLE system option has side effects (e.g. on fonts) which may or may not be acceptable to you.

 

Alternatively, you could specify a list of (at least) 20 colors in the COLORS= option of the GOPTIONS statement (no need for multiple SYMBOL statements then). As a generic list to start with you could simply copy the color list from the device entry and then edit the list as you like (e.g. delete colors that are hardly visible or too similar to others etc.). I did this in the following code example, based on the default color list of the device WIN (obtained by double-clicking entry WIN in the contents of 'Sashelp.Devices' in the CATALOG window):

 

goptions reset=all;

data test;
array y[20];
do x=1 to 3;
  do i=1 to dim(y);
    y[i]=i;
  end;
  output;
end;
run;

symbol v=dot i=join;

goptions colors=(BLACK   RED    GREEN  BLUE    CYAN
                 MAGENTA GRAY   PINK   ORANGE  BROWN
                 LIME    PERU   GOLD   HOTPINK INDIGO
                 KHAKI   PURPLE SILVER SKYBLUE TOMATO);

proc gplot data=test;
   plot (y:)*x / overlay;
run;
quit;

 

Jay54
Meteorite | Level 14

The ODS Styles do not have an inherent limitation of 12 group values.  Most SAS shipped styles do have only up to 12 groups defined, but the style definition itself can have as many as you want.  Actually, many experts in the UI area will attest that having discernable colors greater than eight is a challange anyway, and many new SAS styles have only eight.

 

 

You can derive your own style from one of the popular SAS styles and increase the number of group levels by adding more GRAPHDATAxx elements from 13 to 99.  You can also use the %MODSTYLE macro for this.  see Doc for %MODSTYLE.

 

 Statgraph procedures (GTL and SG) cycle the usage of colors, symbols and patterns to give many more distinct group levels.  84 for markers and 132 for lines.

PTD_SAS
Obsidian | Level 7
Thanks Sanjay.
PTD_SAS
Obsidian | Level 7
Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1681 views
  • 5 likes
  • 3 in conversation