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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 3246 views
  • 1 like
  • 2 in conversation