BookmarkSubscribeRSS Feed
Fluorite | Level 6

I am working on some repeating plots for different subgroups by using the same program with multiple macro calls, the categories in the legend vary in the different subgroups which is data driven.


Here is the code I am using in PROC SGPLOT:


proc sgplot data=final ;
styleattrs datacontrastcolors=(blue red gray);

hbarparm category=&subjid_trtp. response=trtedy/group=MDM2 name="GRPS" barwidth=.5 ;



keyLEGEND "GRPS" /location=outside title="MDM2 Status" linelength=15pt titleattrs=(size=6) VALUEATTRS= (size=6);



Here are the outputs in different subgroups.

Plot 1:


Plot 2:



Here are the related values assigned in the final datasets.

Plot 1:



Plot 2: not sure why "Myxofibrosarcoma^{unicode '207F'x}" is not working in the plot 2,  {unicode '207F'x} is supposed to show the mesh symbol.



Now I want to display the same symbol and color in the legend for each category as the plot 1 shows in all the plots, just wonder how to make it happen. Thanks in advance. 

Super User

The appearance of both of those graphs appear to be using the variable Tumor_types as the y-axis variable.  A strong clue to that is that your values in the Tumor_types variable show the F capitalized at 'Fibro' but your version with the unicode does not.


Quite  often depending on where you attempt to use the escapechar that is not honored and may have to use (*ESC*) instead of the escapechar character as well.


Since you have hidden the name of the actual variable in a macro variable without showing the entire code and where the macro variable &subjid_trtp. gets it's value that is the best that I can do.


When the question is getting a group= variable values to display the same colors and symbols in multiple graphs then the answer is quite often a DATTRMAP= data set that will show the same color, symbol, line type. However that support is not included for bar fill types last time I checked.


To get anything resembling working example you need to provide workable data and all the code involved.

Fluorite | Level 6

Thank you for the inputs. the macro variable &subjid_trtp. is about subject IDs, I think it doesn't matter in this case. I have tried replacing escapechar with (*ESC*) and adding "(*ESC*){unicode xxxx}" to Tumor_types, it doesn't change anything. And I know we can define colors and symbols by using the option DATTRMAP=, but it doesn't work for bar filling as you mentioned.


So my question comes down to if there is a way to define unique colors and patterns for bar filling in PROC SGPLOT across multiple plots. Hope someone has the answer.

Super User

@kc_sas wrote:

Thank you for the inputs. the macro variable &subjid_trtp. is about subject IDs, I think it doesn't matter in this case.

It may be the most important part of this question. The VALUES you show on the Y axis do not appear to come form the  variable that you are attempting to display unicode values with at all. So it will NEVER show them if &subjid_trtp is pointing to the variable Tumor_types. The values you show for Tumor_types does not include the unicode, the escape or even the complete name as far as I can tell.


If you plot the wrong named variable do not expect to get the correct output.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2 in conversation