BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am using GCHART and for each month I am grouping company total sales figures by dept. I defined my patterns for each dept total. However I would like the colors on each chart to be consistent with the dept for each company.

ex. company 1 has dept A - D and is assigned the colors I defined in the patterns. dept A is red
Company 2 has dept B - D so the color I defined as pattern 1 (red) is applied to B

I would like the colors to be consistent across each graph - How would I accomplish the task?
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
If you are now doing by group processing for each month, you may want to consider moving toward an approach like the one shown in this Tech Support note.
http://support.sas.com/kb/24/874.html

It uses a SAS Macro program to guarantee that the ice cream flavors get the right color for the bar chart, even if there is no flavor in a particular group.

The key is specifying an explicit numbered PATTERN statement value in a macro program. Then the correct PATTERN statement is used for every group, so that strawberry is always pink, chocolate is always brown, etc, etc.

cynthia
deleted_user
Not applicable
Thank you - That example you provided is exactly what I was trying to accomplish. However, I keep coming across an issue when applying the method:

Ex. using the following test data:
data company;
input @1 Close $10. @12 person 1. @14 grp $1. @16 sales $3.;
datalines;
B DEPT 1 A 20
A DEPT 1 A 10
P DEPT 2 A 30
B DEPT 4 B 20
C DEPT 5 B 05
C DEPT 7 C 15
P DEPT 7 C 13
A DEPT 7 C 14
;

I would like my output to be a vbar3d gchart for each company that shows the person on the xaxis and total sales on the y axis. Each dept will show the total sales for each person with a different color. In using the macro - does it restrict the use of a subgroup? I keep getting an error. I am able to plot the dept on by company but having some issues plotting the person with the assoicated depts on the same bar.

Any help in the matter would be appreciated.
Cynthia_sas
SAS Super FREQ
Hi:
You may have some other issues with your code. For example, SALES is being read as character, which may give you trouble if you are trying to sum a character variable for the height of the bars. Using SUMVAR=SALES, with SALES as a character variable, I would expect you to get this error:
[pre]
ERROR: Variable sales in list does not match type prescribed for this list.
[/pre]

Also, I only see one company's data??? with the variable CLOSE having the values "B DEPT", "A DEPT", etc. It looks to me like CLOSE is the variable you are using for Department values? But it also looks to me like PERSON starts in position 8, not position 12 and that GRP starts in position 10 and SALES starts in position 12, not 16.

So your problems may partly be caused by reading the input data incorrectly and/or reading the data as character instead of numeric. In the sample data below, I put position numbers above your data to show how I calculated the position numbers. (The position numbers are specified with the '@' in the INPUT statement.)
[pre]
.........1111
1234567890123
B DEPT 1 A 20
A DEPT 1 A 10
P DEPT 2 A 30
[/pre]

If you want to create a "subgroup" chart, then you may not want to use the macro program as it is coded. First, the macro program uses PATTERNID=MIDPOINT -- which is how chocolate always stays brown and strawberry always stays pink. You will probably want the default of PATTERNID=SUBGROUP and before you try to modify that macro program, it would be good to understand how the fills will work for the subgroups -without- a macro program being involved. Normally, every subgroup (every person or every department) -will- get a different color automatically. Since a legend will identify which color (or pattern) corresponds to which subgroup value, it is usually pretty easy to distinguish which subgroups make up a bar.

If you have issues with reading the data or coding PROC GCHART or controlling fill colors or figuring out how a different macro program might be used to help you, you may want to work with Tech Support on this, as they can look at all your real data and your code and help you come to the best solution -- whether it's a macro solution or not.

cynthia

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 707 views
  • 0 likes
  • 2 in conversation