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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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