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

Hello all,

 

I'd like to specfiy different colors for a barchart based on values above and below zero. For example red for greater than zero, green for less than zero, and yellow for zero. I'm relatively new to SAS and using SAS graphics so this may be a rudimentary question.

 

Here is the code I've used so to produce a chart with uniform color:

 

ods graphics / reset border=off width=10in height=8in;

 

proc sgplot data=mydata;

     vbar name / response=percent

          categoryorder=respdesc datalabel datalabelattrs=(size=10pt)

          dataskin=crisp barwidth=0.6 fillattrs=(color=CornFlowerBlue);

     title h=16pt bold color=black "Crowding by Name";

     yaxis label="% Over/Under" labelattrs=(size=11pt)

          values=(-100 to 100 by 5) grid;

     xaxis label="Name";

          xaxis display=(nolabel noline)

               fitpolicy=rotate valuesrotate=vertical valueattrs=(size=11pt); 

run;

title;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I believe you are asking for a "range attribute" data set. This is an auxiliary data set referenced by the rattrmap option on the proc statement that contains information. Here is an example using the SASHELP.CLASS data set.

 

data clrresp;
retain id "myid";
length min $ 5 max $ 5;
input min $ max $ color $ altcolor $ colormodel1 $ colormodel2 $ colormodel3 $;
datalines;
_min_ 90    purple purple .    .      .
90    100   gold   gold   .    .      .
100   _max_ .      .      red  orange yellow
;
run;

proc sgplot data=sashelp.class rattrmap=clrresp;
  vbar age / colorresponse=weight rattrid=myid 
    response=weight stat=mean colorstat=mean;
run;

View solution in original post

3 REPLIES 3
ballardw
Super User

I believe you are asking for a "range attribute" data set. This is an auxiliary data set referenced by the rattrmap option on the proc statement that contains information. Here is an example using the SASHELP.CLASS data set.

 

data clrresp;
retain id "myid";
length min $ 5 max $ 5;
input min $ max $ color $ altcolor $ colormodel1 $ colormodel2 $ colormodel3 $;
datalines;
_min_ 90    purple purple .    .      .
90    100   gold   gold   .    .      .
100   _max_ .      .      red  orange yellow
;
run;

proc sgplot data=sashelp.class rattrmap=clrresp;
  vbar age / colorresponse=weight rattrid=myid 
    response=weight stat=mean colorstat=mean;
run;
atiedt
Fluorite | Level 6
Thanks! Works like a charm.
atiedt
Fluorite | Level 6

 

Here's the successful solution:

 

 

data bardata;

retain id "myid";

length min $ 5 max $ 5;

input min $ max $ color $altcolor $ colormodel1 $ colormodel2 $ colormodel3 $;

datalines;

_min_ 0 green . . . .

0 0 gold gold . . .

1 _max_ red . . . .

;

run;

title h=16pt bold color=black "Crowding";

proc sgplot data=mydata rattrmap=bardata;

vbar name / colorresponse=rcp rattrid=myid

response=rcp categoryorder=respdesc datalabel datalabelattrs=(size=10pt)

dataskin=crisp barwidth=0.6

stat=mean colorstat=mean;

yaxis label="% Over/Under" labelattrs=(size=11pt)

values=(-100 to 100 by 5) grid;

xaxis label="Name";

xaxis display=(nolabel noline)

fitpolicy=rotate valuesrotate=vertical valueattrs=(size=11pt);

run;

title;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

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

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 9911 views
  • 1 like
  • 2 in conversation