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

Hello,

I'm wondering if there is a way to output a table in color by Proc Tabulate.  For example, I would like to have the "year" in different colors in the following code.  Is it doable?

 

proc tabulate data=&Pathogen.;
  Class year state Quarter/ missing;
  var Test ;
  table State*(test*f=10.0),year;
  where Test__groups_ in ('>= 1');
  Label State="State" Test="Test Group >=1 counts";
  Title '&Pathogen._TestGrpLt1_count';
run;
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

you could try to use technique called "traffic lights", here is an example in proc report:

https://support.sas.com/resources/papers/proceedings11/290-2011.pdf

but you can adopt it to tabulate too, which can be seen here:

https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/142-31.pdf

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

12 REPLIES 12
yabwon
Onyx | Level 15
proc tabulate data=&Pathogen.;
  Class year state Quarter/ missing;
  var Test ;
  table State*(test*f=10.0),year*[style=[COLOR=RED]];
  where Test__groups_ in ('>= 1');
  Label State="State" Test="Test Group >=1 counts";
  Title '&Pathogen._TestGrpLt1_count';
run;

did you try something like "style=" ?

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ybz12003
Rhodochrosite | Level 12
Yes, but not all in RED. I would like to get different colors in different years.
yabwon
Onyx | Level 15

you could try to use technique called "traffic lights", here is an example in proc report:

https://support.sas.com/resources/papers/proceedings11/290-2011.pdf

but you can adopt it to tabulate too, which can be seen here:

https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/142-31.pdf

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

To assign colors based on the value of a variable create a custom format for the color you want and associate it with the variable/values you want.

Example (that you can actually run because you should have the SASHELP.CLASS training data set)

 

Proc format;
value $sex_color
'F'='lightred'
'M'='blue'
;
value agegrp
low-12='Preteen'
13-17 ='Teen'
;
value agecolor
low-12 = 'gold'
13-17  = 'red'
;
value  valcolor
low -<60 = 'darkgreen'
60 - high= 'cyan'
;
run;

proc tabulate data=sashelp.class;
   class sex age ;
   classlev sex /style=[color=$sex_color.];
   classlev age /style=[backgroundcolor=agecolor.];
   format age agegrp.;
   var height;
   table sex,
         age*height*mean*[style=[background=valcolor.]]
   ;
run;

 

ChrisHemedinger_0-1701965765173.png

SAS has multiple ways to designate color so is worth looking at the documentation depending on what you actually want.

The formats a examples of how to assign colors and one text (agegrp) based on ranges of values or list of values .

The CLASSLEV will allow you to assign properties to CLASS variables which can keep the actual table syntax a bit cleaner and is very helpful if you are using Proc tabulate to make more than one table with a single procedure call to keep everything set the same without having to duplicate it in the body of the table. Note the use of the Format name associated with the item to color. I show an example of both the text (Color=) and the cell background (backgroundcolor= ) color settings.

 

Also an example of providing appearance change based on the result of a statistic.

 

 

ybz12003
Rhodochrosite | Level 12
It didn't work as I expected. I would like to get the year result background shown in a different color, not just the title.
ybz12003
Rhodochrosite | Level 12
Proc format;
value year color
2021 = 'lighttan'
2022  = 'lightpink'
2023  = 'lightblue'
;
run;

proc tabulate data=&Pathogen.;
  Class year state Quarter/ missing;
  classlev year /style=[backgroundcolor=yearcolor.];
  var Positive Test ;
  table State*(positive*f=10.0*[style=olive] test*f=10.0),year*[style=[background=yearcolor.]]*(quarter all);
  Label State="State" Positive="Total Positive counts" Test="Total Test counts";
  Title '&Pathogen._test#_sum';
run;

 Please let me know where I should modify my code.

Reeza
Super User
Start by fixing errors indicated in the log (proc format)
ballardw
Super User

@ybz12003 wrote:
Proc format;
value year color
2021 = 'lighttan'
2022  = 'lightpink'
2023  = 'lightblue'
;
run;

proc tabulate data=&Pathogen.;
  Class year state Quarter/ missing;
  classlev year /style=[backgroundcolor=yearcolor.];
  var Positive Test ;
  table State*(positive*f=10.0*[style=olive] test*f=10.0),year*[style=[background=yearcolor.]]*(quarter all);
  Label State="State" Positive="Total Positive counts" Test="Total Test counts";
  Title '&Pathogen._test#_sum';
run;

 Please let me know where I should modify my code.


FWIW, I find that the basic pink is awful light and generally use lightred or verylightred instead when I want a pinkish shade.

ybz12003
Rhodochrosite | Level 12

Sample.png

ybz12003
Rhodochrosite | Level 12
The picture shows the result, light color is fine. But all the background results in three years were no difference, neither with Total Positive counts font color.
Reeza
Super User
Note that you specify a colour but not where it applies, font, backgroundcolour, line colour....you're on the right track. Keep playing around.
Cynthia_sas
SAS Super FREQ

Hi:

  You might also want to search in the documentation and on the support web site. For example, in this example

Cynthia_sas_0-1701976073791.png

contained in this Tech Support note: https://support.sas.com/kb/25/401.html

  You can see that the color for each column inherits the color of the header under which the column is nested. This is known as using style=<parent> which is a style override feature of PROC TABULATE. This feature allows you to do either horizontal or vertical "banding" based on the style characteristics that you associate usually with a CLASSLEV header variable.

Cynthia

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 12 replies
  • 1741 views
  • 9 likes
  • 5 in conversation