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

Hi, 

 

Is it possible to color the class variable using different dynamic rules (traffic light coloring) for each column. I am trying to color VAR2 (class1) using one rule, VAR2 (class3) using another rule...

 

traffic.png

 

this code will color the whole table using the same "traffic" format, but I want to have 3 independent traffic rules. 

 

PROC FORMAT;
VALUE TRAFFIC
LOW-<30='RED'
30-50='YELLOW'
50< - HIGH= 'GREEN';
RUN;

PROC TABULATE DATE=INPUT_TABLE;
CLASS VAR1;
CLASS VAR2;
TABLE VAR1, VAR2*[STYLE=[BACKROUND=TRAFFIC.];
RUN;

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Proc TABULATE does not allow you to have individual format per CLASS value. 

 

But you could use Proc REPORT where you do have more control over this. The example below shows how to have different formats for different ACROSS values. The names _c2_, _c3_  etc, are the actual column number in the report. The _dummy computed variable is used to apply the different formats to the proper column.

 


proc format;
  value asia
    0 - 15000 = "cxFF0080"
    15000 - 20000 = "cxC83680"
    20000 - high = "cx916D80"
  ;
  value europe
    0 - 36000 = "cx00FF80"
    36000 - 40000 = "cx00C49D"
    40000 - high = "cx009CB0"
  ;
run;

proc report data=sashelp.cars;
  column type origin, invoice _dummy;
  define type / group;
  define origin / across;
  define invoice / analysis mean;
  define _dummy / computed noprint;
  compute _dummy;
    call define("_c2_", "style", "style={background=asia.}");
    call define("_c3_", "style", "style={background=europe.}");
    call define("_c4_", "style", "style={background=blue}");
  endcomp;
run;

 

View solution in original post

1 REPLY 1
BrunoMueller
SAS Super FREQ

Proc TABULATE does not allow you to have individual format per CLASS value. 

 

But you could use Proc REPORT where you do have more control over this. The example below shows how to have different formats for different ACROSS values. The names _c2_, _c3_  etc, are the actual column number in the report. The _dummy computed variable is used to apply the different formats to the proper column.

 


proc format;
  value asia
    0 - 15000 = "cxFF0080"
    15000 - 20000 = "cxC83680"
    20000 - high = "cx916D80"
  ;
  value europe
    0 - 36000 = "cx00FF80"
    36000 - 40000 = "cx00C49D"
    40000 - high = "cx009CB0"
  ;
run;

proc report data=sashelp.cars;
  column type origin, invoice _dummy;
  define type / group;
  define origin / across;
  define invoice / analysis mean;
  define _dummy / computed noprint;
  compute _dummy;
    call define("_c2_", "style", "style={background=asia.}");
    call define("_c3_", "style", "style={background=europe.}");
    call define("_c4_", "style", "style={background=blue}");
  endcomp;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 667 views
  • 1 like
  • 2 in conversation