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

I am using CALL DEFINE in a PROC REPORT step to control traffic lighting.  Usually when doing this sort of thing the colors are fixed and known.  However I currently am in the situation where I need to use quite a few colors and the style is not known until run time.  I would like to be able to retrieve the available list of colors from the specified style and then use them for the traffic lighting.  Thoughts on how I might do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12

In your current SAS session, the registry holds a list or color-names it considers valid.

My color names list (SAS 9.4) is about 150 long - and I expect you could increase this list.

You can extract the list with a little code.

In the following snippet, beware the quotes (I think office has converted to smart :smileyalert: quotes)

Of course PROC FSLIST expects you are running in old SAS Display Manager

And the export= parameter value below assumes you can write into the current folder.

I expect you would know what to fix if these might be an issue for you....

proc registry export= "colornames.txt" usesashelp start='COLORNAMES' ;

Proc fslist     file= "colornames.txt" ;

run ;

View solution in original post

14 REPLIES 14
Peter_C
Rhodochrosite | Level 12

There is a list of colornames, but you have the opportunity to derive the RBG color value for a blend to use as background fill. Not sure but the HLS schene might be even better......

ArtC
Rhodochrosite | Level 12

Peter, are you saying that while not all colors can be addressed by name, within a style, that all of the RBG colors are available regardless of style?

Ksharp
Super User

retrieve the available list of colors from the specified style

Arthur.C ,

What do you mean by that ? What id available list of colors ?

Xia Keshan

ArtC
Rhodochrosite | Level 12

Perhaps I am doing something else wrong, but i found that not all colors (certainly by name) are available for any given style. 

BrunoMueller
SAS Super FREQ

You can get to the source of a style using

proc template ;
  source styles.htmlblue / EXPAND FILE="";
run;

the EXPAND option will also print the definitions of the parent styles. the one can read in the file and look for color definitions, that might look like:

  'gcdata4' = cx543005
  'gdata4' = cxA9865B
  'gcdata3' = cx01665E
  'gdata3' = cx66A5A0
  'gcdata2' = cxA23A2E
  'gdata2' = cxD05B5B
  'gcdata1' = cx445694
  'gdata1' = cx6F7EB3;
ballardw
Super User

I have been researching this and trial and error for awhile with little luck, at least as of SAS 9.3

I am assuming is that what Art is asking about is being able to reference "gcdata4" or "style:gcdate4" or some such as the color override so that when the style changes the highlighting changes with it.

This behavior would be nice because of the option to set styles in some procedures. If the whole document is prepared with the same document you might be able to query and get the list of colors (but since there is inheritance that isn't necessarily true for all styles) to plug into macro variables.

But if the procedure says to use a different style than that doesn't quite work.

So far the only place I have seen that is in some of the color attribute settings in the SG procedures.

ArtC
Rhodochrosite | Level 12

@Ballardw My problem is, i think, simpler.  the specification of the color itself.

Peter_C
Rhodochrosite | Level 12

Art

have you looked at the macros

%HELPCLR(ALL) ;

Peter_C
Rhodochrosite | Level 12

In your current SAS session, the registry holds a list or color-names it considers valid.

My color names list (SAS 9.4) is about 150 long - and I expect you could increase this list.

You can extract the list with a little code.

In the following snippet, beware the quotes (I think office has converted to smart :smileyalert: quotes)

Of course PROC FSLIST expects you are running in old SAS Display Manager

And the export= parameter value below assumes you can write into the current folder.

I expect you would know what to fix if these might be an issue for you....

proc registry export= "colornames.txt" usesashelp start='COLORNAMES' ;

Proc fslist     file= "colornames.txt" ;

run ;

ArtC
Rhodochrosite | Level 12

This was the piece that I was missing.  Thank you Peter.  I do so enjoy learning from y'all and there is so much to learn!

BrunoMueller
SAS Super FREQ

Colors from styles can be referenced within STYLE= options, see the following example below:

proc report data=sashelp.class;
  column _all_ _dummy;
  define _dummy / computed;

 
compute _dummy / char length=128;
    row+
1;

   
if row > 10 then do;
      row=
1;
   
end;

   
length gdataName $ 32;
    gdataName = cats(
'gdata', row);
    length styleDef $ 128;
    styleDef = cats(
     
"style={background=GraphColors('"
      , gdataName
      ,
"')}"
    );
    _dummy = styleDef;

   
* call define(_row_, "style", "style={background=GraphColors('gdata1')}");
   
call define(_row_, "style", styleDef );
  endcomp;
run;
ArtC
Rhodochrosite | Level 12

For the traffic lighting I would like to conditionally execute the CALL DEFINE.  That part is straight forward.  so far when I build my formats with that specify colors to codes, not all the colors show up.  I have however been using color names ('blue' and such), not RGB colors as @Peter suggested.

Cynthia_sas
SAS Super FREQ

Hi, Art:

  If you use readable color names, then SAS/ODS will go out to the SAS registry to look up the RGB hex equivalent for the name. For example, in the SAS registry, a name of "AliceBlue" would turn into: CXF0F8FF. It used to be that the SAS style templates avoided using color names (except for Black and White) and used RGB hex values for all the colors in the style template. The template itself does generally have a "color list" section, that tells you what the colors in the template are. Those colors are still probably not "named" colors.

  But, the template has 2 ways to specify colors. There are 2 main style elements at play and a 3rd style element that is also at play. The 2 main elements are:

color_list (colors used for tabular output)

graph_colors (colors used for graphical output)

Then for tabular output, there is a separate "colors" style element that maps attribute/nicknames like bylinefg and bylinebg to one of the colors in the color_list style element.


       But the definitive list of colors that will be used by a style can be found in the first 2 style elements. I have copied the 3 sections from the STYLES.DEFAULT template code at the bottom. For me, the challenge is always figuring out what cxD2D9E9 really looks like. So I wrote a program to display it for me.

** 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,'=');
  end;
  else if index(styleinfo,'=') eq 0 then do;
     element_name = ' ';
     color_nm = trim(styleinfo);
  end;
return;
datalines4;
cxd2d9e9
'gcdata3' = cxA08A5D
'gdata2' = cxF2AE49;
'gcdata1' = cx678D67
'gdata1' = cx8FB38F 
  cx6495ed
  #f2ae49
     #b49C6a
   pink
  fred
  grayish red
  very light purplish blue
H14055FF
;;;;
run;
 
title; footnote;
ods html file='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"
           style(column)={font_weight=bold};
    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);
    endcomp;
  run;
ods html close;

But, that still means making 2 passes thru the data to see what the color is and see whether I like it for my purposes. A good set of colors for traffic lighting might be the "ramp" colors in the Graph_Colors style element. Classic traffic lighting generally uses red, yellow and green some some of my faves for this are lightred, lightyellow and lightgreen as possibilities for 3 colors.


Inheritance is a something I wouldn't want to have to worry about, so more power to you if you are using a template that inherits colors from another template. And the other challenge is that if you are dealing with a homegrown style template, somebody could have bypassed the style elements for colors and could have gone directly to the Data element or the RowHeader element and just used a color name directly there. That makes it harder to be dynamic. Because if the color_list and colors elements are telling you that the BYLINEFG is navy blue, but the actual output has purple, then that means that somebody who likes purple went directly to the byline style element and changed the foreground directly.

I wish I had a brilliant idea for you.

Cynthia

     class color_list                                                       
         "Colors used in the default style" /                                
         'fgB2' = cx0066AA                                                   
         'fgB1' = cx004488                                                   
         'fgA4' = cxAAFFAA                                                   
         'bgA4' = cx880000                                                   
         'bgA3' = cxD3D3D3                                                   
         'fgA2' = cx0033AA                                                   
         'bgA2' = cxB0B0B0                                                   
         'fgA1' = cx000000                                                   
         'bgA1' = cxF0F0F0                                                   
         'fgA' = cx002288                                                    
         'bgA' = cxE0E0E0;                                                   
      class colors                                                           
         "Abstract colors used in the default style" /                       
         'headerfgemph' = color_list('fgA2')                                 
         'headerbgemph' = color_list('bgA2')                                 
         'headerfgstrong' = color_list('fgA2')                               
         'headerbgstrong' = color_list('bgA2')                               
         'headerfg' = color_list('fgA2')                                     
         'headerbg' = color_list('bgA2')                                     
         'datafgemph' = color_list('fgA1')                                   
         'databgemph' = color_list('bgA3')                                   
         'datafgstrong' = color_list('fgA1')                                 
         'databgstrong' = color_list('bgA3')                                 
         'datafg' = color_list('fgA1')                                       
         'databg' = color_list('bgA3')                                       
         'batchfg' = color_list('fgA1')                                      
         'batchbg' = color_list('bgA3')                                      
         'tableborder' = color_list('fgA1')                                  
         'tablebg' = color_list('bgA1')                                      
         'notefg' = color_list('fgA')                                        
         'notebg' = color_list('bgA')                                        
         'bylinefg' = color_list('fgA2')                                     
         'bylinebg' = color_list('bgA2')                                     
         'captionfg' = color_list('fgA1')                                    
         'captionbg' = color_list('bgA')                                     
         'proctitlefg' = color_list('fgA')                                   
         'proctitlebg' = color_list('bgA')                                   
         'titlefg' = color_list('fgA')                                       
         'titlebg' = color_list('bgA')                                       
         'systitlefg' = color_list('fgA')                                    
         'systitlebg' = color_list('bgA')                                    
         'Conentryfg' = color_list('fgA2')                                   
         'Confolderfg' = color_list('fgA')                                   
         'Contitlefg' = color_list('fgA')                                    
         'link2' = color_list('fgB2')                                        
         'link1' = color_list('fgB1')                                        
         'contentfg' = color_list('fgA2')                                    
         'contentbg' = color_list('bgA2')                                    
         'docfg' = color_list('fgA')                                         
         'docbg' = color_list('bgA');                                        
      class GraphColors                                                      
         "Abstract colors used in graph styles" /                            
         'gblockheader' = cxd8dae5                                           
         'gcphasebox' = cx000000                                             
         'gphasebox' = cxC2C9D8                                              
         'gczonec' = cxB7C2DA                                                
         'gzonec' = cxCBD3E3                                                 
         'gczoneb' = cxC0CBE4                                                
         'gzoneb' = cxD2D9E9                                                 
         'gzonea' = cxDBE2F1                                                 
         'gcunder' = cx8EB778                                                
         'gunder' = cx8EB778                                                 
         'gcover' = cxEFDF28                                                 
         'gover' = cxEFDF28                                                  
         'gcfinal' = cxC28262                                                
         'gfinal' = cxC28262                                                 
         'gcinitial' = cxEFC328                                              
         'ginitial' = cxEFC328                                               
         'gcother' = cxEFDF28                                                
         'gother' = cxEFDF28                                                 
         'gcmiss' = cx979797                                                 
         'gmiss' = cxD7D0CC                                                  
         'gablock' = cxF1F0F6                                                
         'gblock' = cxD7DFEF                                                 
         'gcclipping' = cxDC531F                                             
         'gclipping' = cxE7774F                                              
         'gcstars' = cx000000                                                
         'gstars' = cxB9CFE7                                                 
         'gcruntest' = cxBF4D4D                                              
         'gruntest' = cxCAE3FF                                               
         'gccontrollim' = cxBFC7D9                                           
         'gcontrollim' = cxE6F2FF                                            
         'gcerror' = cx000000                                                
         'gerror' = cxB9CFE7                                                 
         'gcpredictlim' = cx003178                                           
         'gpredictlim' = cxB9CFE7                                            
         'gcpredict' = cx003178                                              
         'gpredict' = cx003178                                               
         'gcconfidence2' = cx780000                                          
         'gcconfidence' = cx003178                                           
         'gconfidence2' = cxE7B9B9                                           
         'gconfidence' = cxB9CFE7                                            
         'gcfit2' = cx780000                                                 
         'gcfit' = cx003178                                                  
         'gfit2' = cx780000                                                  
         'gfit' = cx003178                                                   
         'gcoutlier' = cx000000                                              
         'goutlier' = cxB9CFE7                                               
         'gcdata' = cx000000                                                 
         'gdata' = cxB9CFE7                                                  
         'greferencelines' = cx808080                                        
         'gheader' = colors('docbg')                                         
         'gconramp3cend' = cxFF0000                                          
         'gconramp3cneutral' = cxFF00FF                                      
         'gconramp3cstart' = cx0000FF                                        
         'gramp3cend' = cxDD6060                                             
         'gramp3cneutral' = cxFFFFFF                                         
         'gramp3cstart' = cx6497EB                                           
         'gconramp2cend' = cx6497EB                                          
         'gconramp2cstart' = cxF3F7FE                                        
         'gramp2cend' = cx5E528B                                             
         'gramp2cstart' = cxEDEBF6                                           
         'gtext' = cx000000                                                  
         'glabel' = cx000000                                                 
         'gborderlines' = cx000000                                           
         'goutlines' = cx000000                                              
         'ggrid' = cxECECEC                                                  
         'gaxis' = cx000000                                                  
         'gshadow' = cx000000                                                
         'glegend' = cxFFFFFF                                                
         'gfloor' = cxFFFFFF                                                 
         'gwalls' = cxFFFFFF                                                 
         '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;                                               

ArtC
Rhodochrosite | Level 12

Thank you Cynthia

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 14 replies
  • 1788 views
  • 6 likes
  • 6 in conversation