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

Is there anyway to assign color to each stacked bar just like using pattern in a pie chart (gchart). I want these colors to be outputted in a particular order. I will be grateful with any help

1 ACCEPTED SOLUTION

Accepted Solutions
danielduval0
SAS Employee

Or use this example:

 

http://support.sas.com/kb/43/731.html

 

Basically, what you need is the data attrmap step which contains a datalines statement containing the variables you would like to group by color:

 

data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is FLAVOR */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */

input id $ value $10. @19 fillcolor $8.;
datalines;
flavor Vanilla beige
flavor Chocolate cx663D29
flavor Strawberry pink
;
run;

 

Then, in your proc sgplot statement:

 

/* The DATTRMAP option references the attribute map data set */
proc sgplot data=icecream dattrmap=attrmap;
format sex $fmt.;
/* The ATTRID option references the name of the attribute map */
vbar sex / group=flavor response=count groupdisplay=cluster
dataskin=pressed attrid=flavor;
xaxis display=(nolabel noticks);
yaxis label='Count of Participants';
keylegend / title='Ice Cream Flavor';
run;

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

View solution in original post

5 REPLIES 5
danielduval0
SAS Employee

See the following post:

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/PROC-SGPLOT-How-to-use-Custom-Colors-in-St...

 

Let me know if this does not answer your question!

 

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

danielduval0
SAS Employee

Or use this example:

 

http://support.sas.com/kb/43/731.html

 

Basically, what you need is the data attrmap step which contains a datalines statement containing the variables you would like to group by color:

 

data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is FLAVOR */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */

input id $ value $10. @19 fillcolor $8.;
datalines;
flavor Vanilla beige
flavor Chocolate cx663D29
flavor Strawberry pink
;
run;

 

Then, in your proc sgplot statement:

 

/* The DATTRMAP option references the attribute map data set */
proc sgplot data=icecream dattrmap=attrmap;
format sex $fmt.;
/* The ATTRID option references the name of the attribute map */
vbar sex / group=flavor response=count groupdisplay=cluster
dataskin=pressed attrid=flavor;
xaxis display=(nolabel noticks);
yaxis label='Count of Participants';
keylegend / title='Ice Cream Flavor';
run;

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

Anita_n
Pyrite | Level 9

 Thanks for the idea. I will apply it and leave a feedback

Anita_n
Pyrite | Level 9

Thanks it worked fine.

danielduval0
SAS Employee

Great news! I am glad I was able to help.

 

 

 

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

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
  • 5 replies
  • 2628 views
  • 1 like
  • 2 in conversation