BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
A_Kh
Lapis Lazuli | Level 10

Hello Community, 

My group values are not getting consistently colored across all groups. I found a similar topic with PROC SGPLOT where   @djrisks gave a solution using Discrete Attribute Maps method. I'm wondering if this technique works for SGPANEL as well or there are different ways to get consistent colors by group values.  

For clarity I used the below code (where 'yellow' represents  Cylinders=10  in SUV group and Cylinders=12  in Sports group. I need 'yellow' to represent only Cylinders=10). 

		proc sort data=sashelp.cars out=cars; by origin type; run; 

		proc freq data=cars;
			where cylinders in (4 5 6 8 10 12); 
			by origin;
			tables type*cylinders/out=have totpct outpct;
		run; 
		
		title 'SUV cars';
		proc SGPANEL data=have;
			where type eq "SUV";
			panelby origin;
			styleattrs datacolors=(blue red green yellow orange purple);
			vbar type / response=pct_row group=cylinders groupdisplay=stack;
			colaxis discreteorder=data valueattrs=(size=7pt) fitpolicy=rotate label="Cylinders";;
			rowaxis grid values=(0 to 100 by 10) label="Percent";
		run;

		title 'Sports cars';
		proc SGPANEL data=have;
			where type eq "Sports";
			panelby origin;
			styleattrs datacolors=(blue red green yellow orange purple);
			vbar type / response=pct_row group=cylinders groupdisplay=stack;
			colaxis discreteorder=data valueattrs=(size=7pt) fitpolicy=rotate label="Cylinders";;
			rowaxis grid values=(0 to 100 by 10) label="Percent";
		run;
		title; 

Any help much appreciated. 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Or for your this special case. Try options SPARSE :
tables type*cylinders/out=have totpct outpct;

-->
tables type*cylinders/out=have totpct outpct sparse;

View solution in original post

4 REPLIES 4
A_Kh
Lapis Lazuli | Level 10

Thank you for the quick reply and tips!
As documentation focused on SGPLOT procedure, I couldn't replicate it in my SGPANEL.. But appreciate sharing those info with me!!

Ksharp
Super User
Or for your this special case. Try options SPARSE :
tables type*cylinders/out=have totpct outpct;

-->
tables type*cylinders/out=have totpct outpct sparse;

A_Kh
Lapis Lazuli | Level 10

Thank you so much, it works perfectly!

And the most efficient way.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 896 views
  • 7 likes
  • 3 in conversation