BookmarkSubscribeRSS Feed
sfo
Quartz | Level 8 sfo
Quartz | Level 8

Hello,

 

Is is possible if in the below example from SAS support, I can only display cat1. So, my first bar will have 60% in midpoint=1, 2nd bar as 30% and 3rd bar as 80%? My data is the same and each bar should still calculate the %of each cat for each midpoint, but should only display %for cat=1.

 

example: http://support.sas.com/kb/41/976.html

 

Thanks

 

6 REPLIES 6
Reeza
Super User

Do you need to calculate the percentages or is it already calculated, as in the example?

 

In the example above you can limit your data to category=CAT1 and use a vbar to create a plot.

 

You could also pre calculate the percentages and then use proc sgplot with vbar or a gchart graph. 

 

If you post some sample data someone can help with code.

sfo
Quartz | Level 8 sfo
Quartz | Level 8

Thanks for the reply.

 

I was able to prepare the graph but now I have another problem.

 

Is there a way in proc gchart to assign specific colors to the bars? I am trying annotation, but its not working.

Reeza
Super User

You can use the methods here:

 

http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#colors-specify-co...

 

Changing the style is relatively easily. 

 

If you're just doing a bar chart, you may want to consider PROC SGPLOT instead, it has better graphics.

 

If your question is answered, please mark the question answered and ask your new questions in a new thread.

ballardw
Super User

The old school approaches, which GCHART uses, if you want to display a specific color for a specific value you need to know the Order of your data as the first displayed with use the the first color definition (if only using style) or the first PATTERN statement. You would define separate pattern statements:

Pattern1 color=green;

Pattern2 color=gold;

Pattern3 color=blue;

... for as many patterns as you need. You will want to look up the different ways to define colors if the named colors don't work out quite as you want. SAS support use of RGB, CMYK, HSV, HSB, gray scale, named and SAS Color Naming System (CNS) which uses names similar to brightreddishyellow.

sfo
Quartz | Level 8 sfo
Quartz | Level 8
Thanks for the reply. I did a workaround using macros and is working.

Priya.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
DanH_sas
SAS Super FREQ

I'm not sure of your SAS version, but try these examples using attrmaps and percentages using SGPLOT.

 

data gendermap;
retain id "gender";
length fillcolor $ 9;
input value $ fillcolor $;
cards;
F pink
M lightblue
;
run;

 

/* percentages across all midpoints */
proc sgplot data=sashelp.class dattrmap=gendermap;
vbar age / response=height group=sex attrid=gender stat=percent groupdisplay=cluster datalabel;
run;

 

/* Percentages within each midpoint */
proc sgplot data=sashelp.class dattrmap=gendermap pctlevel=group;
vbar age / response=height group=sex attrid=gender stat=percent groupdisplay=cluster datalabel;
run;

/* Percentages within each midpoint and stacked groups*/
proc sgplot data=sashelp.class dattrmap=gendermap pctlevel=group;
vbar age / response=height group=sex attrid=gender stat=percent seglabel;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 2068 views
  • 0 likes
  • 4 in conversation