BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ewilliamson
Calcite | Level 5

I am trying to use the SGPLOT procedure to create a stacked horizontal bar chart with four categories and apply a color scheme using the attrid statement.

 

In order to get the four categories in the proper order (rather than alphabetical), each category was assigned a numeric variable (1-4) and a format statement is used to convert the numeric variable back into the category label.

 

The issue is that I can either get the format to work but the attrid statement won't work to assign the appropriate colors or the attrid statement works to assign the colors and I am left with (1,2,3,4) in my legend.

 

The first statement produces an output with the appropriate values for label but not the colors specified by the evh type

 

proc sgplot data=combined5 dattrmap=formatdw.evhstyle;
format value valfmt.;
hbar &sumvar. / response=pcs1 stat=sum
group=value groupdisplay=stack nooutline attrid=evh;
title "Primary Care Services by Type";
run;

SAS2.JPG

 

The second statement produces a graph with the appropriate colors but leaves (1,2,3,4) in the legend as the values used to order the stacked bars

 

proc sgplot data=combined5 dattrmap=formatdw.evhstyle;
hbar &sumvar. / response=pcs1 stat=sum
group=value groupdisplay=stack nooutline attrid=evh;
title "Primary Care Services by Type";
run;

sas1.JPG

Ideally, I'd like the bars stacked in the proper order, with the color scheme applied and the service types labeled in the legend. Thanks in advance for any help.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the formatted group values in your dattrmap dataset, sort your data by your numeric variable, and use grouporder=data in the hbar statement. 

PG

View solution in original post

3 REPLIES 3
WarrenKuhfeld
Rhodochrosite | Level 12

I don't know the answer, and there is not enough code here for me to easily reconstruct what you are doing.  However, I can say that one of the standard legend tricks is to make an invisible plot that has the legend you want and overlay it with a visible plot that makes the graph that you want (and don't show the legend for it). 

 

Also, in either the latest release or the second latest, there is a legenditem statement that is very cool and lets you control precisely what is in the legend.  If no one posts better ideas, you might try those.

Reeza
Super User
It would be helpful if you can replicate this using a SASHELP table or provide some sample data so we can test solutions rather than make some generic suggestions.
PGStats
Opal | Level 21

Use the formatted group values in your dattrmap dataset, sort your data by your numeric variable, and use grouporder=data in the hbar statement. 

PG

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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
  • 2314 views
  • 0 likes
  • 4 in conversation