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