Data visualization with SAS programming

Subgroup in proc GCHART

Reply
Contributor sfo
Contributor
Posts: 66

Subgroup in proc GCHART

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

 

Grand Advisor
Posts: 16,393

Re: Subgroup in proc GCHART

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.

Contributor sfo
Contributor
Posts: 66

Re: Subgroup in proc GCHART

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.

Grand Advisor
Posts: 16,393

Re: Subgroup in proc GCHART

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.

Grand Advisor
Posts: 9,748

Re: Subgroup in proc GCHART

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.

Contributor sfo
Contributor
Posts: 66

Re: Subgroup in proc GCHART

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. -##
SAS Super FREQ
Posts: 864

Re: Subgroup in proc GCHART

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;

Post a Question
Discussion Stats
  • 6 replies
  • 489 views
  • 0 likes
  • 4 in conversation