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

I want both graphs to have the same color for the class variable. For the histogram, the coloring is set by 

styleattrs DATACOLORS=(blue red )

 But how do I set the same colors to differentiate between the classes in the vbar?

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red );
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;
proc sgplot data=&_input.; styleattrs DATACOLORS=(blue red ) ; title "Mean &response. per &class. "; vbar &class. / response=&response. stat=Mean name='Bar' filltype= solid datalabel; yaxis grid; run;

 vbar.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;

proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title  "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;

Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same. 

SGPlot13.png

 

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;

proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title  "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;

Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same. 

SGPlot13.png

 

 

Ullsokk
Pyrite | Level 9

Thank you, didnt realise I needed to specify groups= , thought that would be implicit. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 17204 views
  • 0 likes
  • 2 in conversation