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

Hello,

I've created two graphs from my data, one an overlaid histogram (HISTOGRAM statement) and one a stacked histogram (SGPANEL statement). Here is my code:

 

proc sgplot data=Surveys;styleattrs datacolors=(blue CXFF00FF);
where gender~='';styleattrs backcolor=white wallcolor=white;
format gender $gender.;histogram Weeks / group=gender transparency=0.5;
xaxis label='Weeks' LABELATTRS=(size=14) VALUEATTRS=(size=13);
keylegend  / title='Gender' TITLEATTRS=(size=16) valueattrs=(size=12); 
yaxis LABELATTRS=(size=14) VALUEATTRS=(size=13) grid GRIDATTRS=(color=LIGGR);run;

proc sgpanel data=Surveys;
styleattrs datacolors=(blue CXFF00FF) datacontrastcolors=(blue CXFF00FF);
where gender~='';  styleattrs  backcolor=white wallcolor=white;
format gender $gender.;panelby gender / rows=2 layout=rowlattice;
 histogram Weeks;
  COLAXIS label='Weeks' LABELATTRS=(size=14) VALUEATTRS=(size=13);
rowaxis  LABELATTRS=(size=14) VALUEATTRS=(size=13) grid GRIDATTRS=(color=LIGGR);
keylegend  / title='Gender' TITLEATTRS=(size=16) valueattrs=(size=12); run;

Here are the graphs that come out:

confooseddesi89_2-1693866603788.png

 

confooseddesi89_3-1693866610621.png

 

The overlaid histogram (first graph) comes out the way I need with regard to the colors of the bars for each group (blue for male and a purplish color, CXFF00FF, for females). However, I can't figure out how to color the SGPANEL(second graph) the same way, despite using "styleattrs datacolors=(blue CXFF00FF) datacontrastcolors=(blue CXFF00FF)". I've Googled around and can't seem to find a solution. Can you help? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

You need to include the GROUP= option on the HISTOGRAM statement in PROC SGPANEL. To get exactly the same colors/transparency as in the first image, use

histogram Weeks / group=gender transparency=0.5;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

You need to include the GROUP= option on the HISTOGRAM statement in PROC SGPANEL. To get exactly the same colors/transparency as in the first image, use

histogram Weeks / group=gender transparency=0.5;

Ksharp
Super User
/*Using GROUP= option*/
proc sgpanel data=sashelp.heart;
panelby sex / rows=2 layout=rowlattice;
histogram weight/group=sex;
run;

Ksharp_0-1693913300568.png

 

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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