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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2774 views
  • 1 like
  • 2 in conversation