BookmarkSubscribeRSS Feed
kc_sas
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);

run;

 

Here are the outputs in different subgroups.

Plot 1:

1.png

Plot 2:

3.png

 

Here are the related values assigned in the final datasets.

Plot 1:

2.png

 

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.

4.png

 

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. 

3 REPLIES 3
ballardw
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.

kc_sas
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.

ballardw
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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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