The SAS Output Delivery System and reporting techniques

Output the SAS/GRAPH colors for an ODS STYLE to a data set

Frequent Contributor
Posts: 148

Output the SAS/GRAPH colors for an ODS STYLE to a data set

When I run, for example, PROC GCHART, and use different ods styles, I get different colors. Is there a way to output to a data set the color list for a specific ODS STYLE?

Posts: 8,743

Re: Output the SAS/GRAPH colors for an ODS STYLE to a data set

Hi, Don:

  Generally, if you look at a style template, you will see all the colors (GraphColors or Colors) in a color list at the top of the template. Mostly the colors will be of the form cxRRGGBB (as hex values). The colors are set up in a list of attributes and color values, so you would see something like this (pasted from ANALYSIS style):


style GraphColors /

'gablock' = cxFFFDF7

'gblock' = cxEEF4EE

'gcclipping' = cxDC531F

'gclipping' = cxE7774F

'gcstars' = cx588458

'gstars' = cxB3D2B3

'gcruntest' = cxE7774F

'gruntest' = cxE6E6CC

'gccontrollim' = cxCCCC97

'gcontrollim' = cxFFFFE3

'gdata' = cxB3D2B3

'gcdata' = cx588458

'goutlier' = cx000000

'gcoutlier' = cx000000

'gfit2' = cxD18000

'gfit' = cx678D67

'gcfit2' = cxD18000

'gcfit' = cx678D67

'gconfidence2' = cxF5DAC1

'gconfidence' = cxDEDBC8

'gcconfidence2' = cx9F8777

'gcconfidence' = cxA5A18F

'gpredict' = cx678D67

'gcpredict' = cx678D67

'gpredictlim' = cxEEEDE3

'gcpredictlim' = cxEEEDE3

'gerror' = cx000000

'gcerror' = cx000000

'ginsetheader' = colors('headerbg')

'ginset' = colors('databg')

'greferencelines' = cxA5A5A5

'gheader' = colors('docbg')

'gconramp3cend' = cx3D793D

'gconramp3cneutral' = cxC8C1AE

'gconramp3cstart' = cxD18000

'gramp3cend' = cx6EA16E

'gramp3cneutral' = cxB4CBAA

'gramp3cstart' = colors('docbg')

'gconramp2cend' = cxD18000

'gconramp2cstart' = cxFFFFD4

'gramp2cend' = cx6EA16E

'gramp2cstart' = colors('docbg')

'gtext' = cx000000

'glabel' = cx000000

'gborderlines' = cx4F493B

'goutlines' = cx000000

'ggrid' = cxEFEDDD

'gaxis' = cx4F493B

'gshadow' = cxB4B4B4

'gfloor' = cxE4E4E4

'glegend' = cxFFFFFF

'gwalls' = cxFFFFFF

'gcdata12' = cx868686

'gdata12' = cxA4A4A3

'gcdata11' = cx746644

'gdata11' = cx8A7A53

'gcdata10' = cx699AA1

'gdata10' = cx98C7CE

'gcdata9' = cxE6DA9E

'gdata9' = cxFAEEAF

'gcdata8' = cx6882A8

'gdata8' = cx8AA4C9

'gcdata7' = cxBEB794

'gdata7' = cxD9D2AD

'gcdata6' = cxA5BDD7

'gdata6' = cxBDD5EF

'gcdata5' = cx8E6C93

'gdata5' = cxA47DAA

'gcdata4' = cxB3C54D

'gdata4' = cxCBD786

'gcdata3' = cxA08A5D

'gdata3' = cxB49C6A

'gcdata2' = cxD18000

'gdata2' = cxF2AE49

'gcdata1' = cx678D67

'gdata1' = cx8FB38F;

  So for example the color 'gdata1' is an attribute whose color is set to cx8FB38F -- then later in the template, you will find that GDATA1 is referenced in the sections for other style elements, like this (f you don't find gdata1 used in STYLES.ANALYSIS, you may have to check in the parent template to see where GDATA1 is used):

class GraphData1 /

markersymbol = "circle"

linestyle = 1

contrastcolor = GraphColors('gcdata1')

color = GraphColors('gdata1');

  Or, you can look in these sections in the doc to see which style element is used for which piece of the graph (note that it might be different for device-based vs template based graphs): (device-based graphics or SAS/GRAPH) (device-based graphics or SAS/GRAPH) (template-based graphics or ODS GRAPHICS) (template-based graphics or ODS GRAPHICS)

  This program doesn't show you where a color is used, but it will reveal the colors and what they are if you cut and paste a color list from a style template into this program.

  I didn't do anything fancy like read the whole style template to find all the colors or where they were used, but I think the program will get you started.


** To use this program either: ;
** 1) cut and paste attribute = color information from the ;
**    style template after the datalines4 statement.;
** 2) Or, put just a color name on a line;
**    can be in CX format, HTML #, Gray, CMYK, HLS, HSV or CSN format;
**    or "verbose" color format;
** If a color name is not valid, there will not be any color on that row.;
** as shown in the obs where the color specified was FRED.;
**    ;
data whatcolor;
  length styleinfo $60  element_name $30 color_nm $30;
  infile datalines length=lg;
  input styleinfo $varying. lg;

  ** get rid of semi-colons if cut and pasted from code;
  origstyle = compress(styleinfo,';');

  ** left justify the value ;
  styleinfo = compress(left(origstyle));

  ** if color is attribute = value, then split;
  ** the string apart;
  if index(styleinfo,'=') gt 0 then do;
     element_name = scan(styleinfo,1,'=');
     color_nm = scan(styleinfo,2,'=');
  else if index(styleinfo,'=') eq 0 then do;
     element_name = ' ';
     color_nm = trim(styleinfo);
'gcdata3' = cxA08A5D
'gdata2' = cxF2AE49;
'gcdata1' = cx678D67
'gdata1' = cx8FB38F 
  grayish red
  very light purplish blue

ods html file='c:\temp\whatcolor.html' style=sasweb;
  proc report data=whatcolor nowd;
    title 'Showing Color Values';
    column origstyle color_nm color_nm=c2 element_name ;
    define origstyle / display "Original Color Data"
    define color_nm / display 'What Color';
    define c2 / display 'Color Name Used';
    define element_name / display 'Element or Color Type';
    compute color_nm ;
       sval = 'style={foreground='||color_nm||
                    ' background='||color_nm||' font_size=12pt}';
       call define(_COL_,'style',sval);
ods html close;



Frequent Contributor
Posts: 148

Re: Output the SAS/GRAPH colors for an ODS STYLE to a data set

Thanks Cynthia. But this was not really my question. Let me try again using the example you posted with a little more background about what  I am trying to do. I create a data set that has a list of styles as follows:

ods output styles=styleList;

proc template;

     list styles;


ods _all_ close;

In a UI (for a stored process), I present this list to the user and they pick a style. In the next chained stored process I pass the selected style (e.g., available as &style) and what I want is the list of gccolors as a data set.

Using your example, I've played around with a few variations (unfortunately, I am not, by any means, terribly conversant in PROC TEMPLATE), but can't seem to get anything to give me a list of colors.

Posts: 8,743

Output the SAS/GRAPH colors for an ODS STYLE to a data set


  The PROC TEMPLATE code will only give you a list of styles, not what is inside those styles. To get the "source code" for the template, you'd have to use this form of PROC TEMPLATE code:


proc template;

  source styles.analysis /store=sashelp.tmplmst



the above code will take the ANALYSIS style and "decompile" the template source from the item store. Then the decompiled source code will be put into c:\temp\analysis.txt -- but that doesn't put it into a SAS dataset yet -- just into an ASCII text file that you could read with a DATA step program.

For grouped bar or pie or plot charts, the relevant style attributes being used are gdata1-gdata12. I guess you could take your value for &STYLE and then get the source code and parse out gdata1-gdata12 to get the list of particular colors used for grouped data.

  The template code is stored in an "item store" which is like the SAS registry -- it is a form of SAS file, but NOT a SAS data set.

  Does that help, at all?


Frequent Contributor
Posts: 148

Output the SAS/GRAPH colors for an ODS STYLE to a data set

Absolutely helps Cynthia. Thx!.

I need the values in a macro variable for a stored process and the following code does this:

filename colors catalog 'work.tempfile.tempfile.source';

proc template;

  source styles.analysis /store=sashelp.tmplmst



data _null_;

retain colorList;

length colorlist $256;

infile colors;


if index(_infile_,"'gdata");

color = strip(scan(_infile_,2,'='));

color = '#' || substr(color,3,6);

/* create a cumulative list of colors */

colorList = catx(' ',colorList,color);

/* update a macro var with the new list of values */

call symputx('colorList',colorList);


%put &colorList;

I will likely not run this code as part of the stored process. I will tweak it a bit an save a data set with one obs per style with the list of colors. My stored process can then use that data set.

Thx again!!!!!

Ask a Question
Discussion stats
  • 4 replies
  • 2 in conversation