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

Hello everyone, 

 

I don't know how to change the color only for one bar (for example just for desks) and keep the same color for all the other ones? Could you please help me ? Thank you very much 

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/Drawing-confidence-intervals-in-gplot-usin...

 

 

data error;
  input Product $  Revenue Upper Lower;
  datalines;
Desks  2000 2200  1800
Chairs 1500 1700  1300
Lamps  1200 1100  1300
;
run;

proc template;
  define statgraph errorbars;
    begingraph;
      entrytitle 'Product Revenue';
      layout overlay / yaxisopts=(offsetmin=0) xaxisopts=(display=(ticks tickvalues line));
     barchart x=product y=revenue;
        scatterplot x=product y=revenue / yerrorupper=upper yerrorlower=lower markerattrs=(size=0);
      endlayout;
    endgraph;
  end;
run;

ods listing;
ods graphics / reset width=5in height=3in imagename='Error';
proc sgrender data=error template=errorbars;
run;



 

example.png
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, the two things jump to mind:

- Use a proc template step to define a styles for the graph, and set the colors for group 1 to be one color, then the other groups to the same color.

- Use two separate graph statements, one barchart statement for the first group setting the color, then another barchart statement for the rest of the data, setting the color there.

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, the two things jump to mind:

- Use a proc template step to define a styles for the graph, and set the colors for group 1 to be one color, then the other groups to the same color.

- Use two separate graph statements, one barchart statement for the first group setting the color, then another barchart statement for the rest of the data, setting the color there.

 

SoumeyaPierret
Calcite | Level 5

Hey RW9, 

Thank you very very muuuuuuuuuuuuuuch, it worked !!!!!

ballardw
Super User

Add a group variable that has one value for the "desks" and another for everything else and use the GROUP option on the scatterplot statement to use that variable to display different color (and/or marker)

SoumeyaPierret
Calcite | Level 5

Thanks ballardw 😉

DanH_sas
SAS Super FREQ

Another approach to consider is using a discrete attrmap and setting the group variable on the barchart to be the same as the category variable. In the attrmap, set the one category value to the desired color and the other values to another color. The benefit of this approach is that it will work regardless of data order.

 

Hope this helps!

Dan

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 2751 views
  • 0 likes
  • 4 in conversation