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
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®
See the following post:
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®
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®
Thanks for the idea. I will apply it and leave a feedback
Thanks it worked fine.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.