BookmarkSubscribeRSS Feed
lbarwick
Quartz | Level 8

I am creating a grouped bar chart (9.4 M4) using sgplot and vbar statement. I am using the Printer style and default colors for the clustered groups:

example1.PNG

 

I am trying to figure out the specific color codes in the above chart so that I can use them elsewhere in my reports so everything is consistent. The closest I got was the cx6F6EB3 code for the blue:

 

example2.PNG

I tried outputting the style elements to a txt file but this seems to be a very cumbersome way of figuring out the color codes...is this my only option?

8 REPLIES 8
Reeza
Super User

I assume you mean via PROC TEMPLATE? The colours are stored in GRAPHDATA1, GRAPHDATA2, so you could probably write another script to parse that out. Not sure if there's another way to access the GRAPHDATA colour elements. 

 


@lbarwick wrote:

I am creating a grouped bar chart (9.4 M4) using sgplot and vbar statement. I am using the Printer style and default colors for the clustered groups:

example1.PNG

 

I am trying to figure out the specific color codes in the above chart so that I can use them elsewhere in my reports so everything is consistent. The closest I got was the cx6F6EB3 code for the blue:

 

example2.PNG

I tried outputting the style elements to a txt file but this seems to be a very cumbersome way of figuring out the color codes...is this my only option?


 

PaigeMiller
Diamond | Level 26

If you are good with Photoshop, you can determine the exact RGB values of the original plot, and then use those in subsequent plots.

 

A much simpler solution is to specify your own colors in the original plot rather than the default colors, and then there's no problem using those colors in subsequent plots.

--
Paige Miller
DanH_sas
SAS Super FREQ

For your non-grouped bar chart, you should be able to reference the style element directly. Trying something like the following:

 

proc sgplot data=sashelp.class;
vbar age / fillattrs=GraphData1;
run;

Hope this helps!

Dan

Reeza
Super User
I suspect what you're trying to do is create a consistent colour per group across various charts. You would want to use a DATA ATTRIBUTE map (assuming you're using SGPLOT, not SAS/GRAPH). Additionally, if you have SAS Enterprise Guide it has a style manager. So within the style manager you can see the color codes. If you don't have EG send me a DM with the style name you're using and I'll send you the color codes.
JeffMeyers
Barite | Level 11

This is not going to be a very programmatic answer, but something I've had to do in the past when given an image to match colors with is to simply open it with Microsoft Paint. I use the eye dropper to get the color I'm looking for, select "Edit Colors" and I get a menu that shows me the Hue, Saturation, and Luminescence as well as the Red, Green and Blue values. I can use these values to find the appropriate hex color number based on the code in the following link:  Blog on SAS Colors.

ballardw
Super User

The following is from the style template source for style.printer  from SAS 9.4m4.

   class GraphColors
      "Abstract colors used in graph styles" /
      'gcdata12' = cxF9DA04
      'gcdata11' = cxB38EF3
      'gcdata10' = cx47A82A
      'gcdata9' = cxD17800
      'gcdata8' = cxB26084
      'gcdata6' = cx7F8E1F
      'gcdata7' = cx2597FA
      'gcdata4' = cx543005
      'gcdata5' = cx9D3CDB
      'gcdata3' = cx01665E
      'gcdata2' = cxB2182B
      'gcdata1' = cx2A25D9
      'gdata12' = cxDDD17E
      'gdata11' = cxB7AEF1
      'gdata10' = cx87C873
      'gdata9' = cxCF974B
      'gdata8' = cxCD7BA1
      'gdata6' = cxBABC5C
      'gdata7' = cx94BDE1
      'gdata4' = cxA9865B
      'gdata5' = cxB689CD
      'gdata3' = cx66A5A0
      'gdata2' = cxDE7E6F
      'gdata1' = cx7C95CA;

The GDATA entries should be the colors and GCDATA the contrast colors which may be outlines and such. The suffix, 1, 2, 3 etc is the order they are applied unless overwritten

 

lbarwick
Quartz | Level 8

I ended up just trying each of the color codes from the template output. It ended up being gdata1 - cx7C95CA.

 

I tried @DanH_sas suggestion of specifying gdata1 as the fillattrs but I got a warning that the color code was not recognized. 

 

@Reeza the Data attribute map sounds interesting. I am using sgplot but don't have EG.

Rick_SAS
SAS Super FREQ

I echo @Reeza and @DanH_sas that you should use GraphData1, etc, when possible. If you can't do it, then a programmatic solution is explained in the blog post "What colors does PROC SGPLOT use for markers?" The article illustrates the idea by using the "statistical" style, but you can replace that with any other style.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 4362 views
  • 6 likes
  • 7 in conversation