Hi,
I am using proc sgpanel to make a panel of vertical bar graph, and my problem is that the unique groups levels all get the same color. I have tried many different variation of codes but have not been able to create different colors for the 2 levels of the group variable.
Here is my data set: data=freqbone2
Obs |
mp |
thickness |
tooth |
frequency |
1 |
1 |
1 |
Canine |
95.4 |
2 |
1 |
1 |
Lateral incisor |
95.3 |
3 |
1 |
1 |
Central incisor |
96.8 |
4 |
1 |
2 |
Canine |
4.6 |
5 |
1 |
2 |
Lateral incisor |
4.7 |
6 |
1 |
2 |
Central incisor |
3.2 |
7 |
2 |
1 |
Canine |
3.6 |
8 |
2 |
1 |
Lateral incisor |
23.8 |
9 |
2 |
1 |
Central incisor |
16.3 |
10 |
2 |
2 |
Canine |
96.4 |
11 |
2 |
2 |
Lateral incisor |
76.2 |
12 |
2 |
2 |
Central incisor |
83.7 |
13 |
3 |
1 |
Lateral incisor |
0.5 |
14 |
3 |
1 |
Central incisor |
1.1 |
15 |
3 |
2 |
Canine |
100.0 |
16 |
3 |
2 |
Lateral incisor |
99.5 |
17 |
3 |
2 |
Central incisor |
98.9 |
Below is the panel that is formed from the 3 different programs listed below. Can someone please help. I just want to have different colors for each of the 2 levels of the group variable “thickness”. All these 3 program yield the same figure shown below.
Program 1:
proc sgpanel data=freqbone2 ;
panelby mp /novarname headerattrs=(size=15pt)
layout=columnlattice onepanel;
vbar tooth / response= frequency
group=thickness groupdisplay=cluster
dataskin=crisp transparency=0.1 fillattrs=graphdata10;
colaxis valueattrs=(size=8pt weight=bold)
label='Tooth type' labelattrs=(size=18pt weight=bold);
rowaxis valueattrs=(size=14pt) label='Frequency sites'
labelattrs=(size=18pt weight=bold) grid;
format tooth tooth3_. mp mp_.;
run;
Program 2:
proc sgpanel data=freqbone2;
styleattrs datacolors=(red green);
panelby mp /novarname headerattrs=(size=15pt)
layout=columnlattice onepanel;
vbar tooth / response= frequency
group=thickness groupdisplay=cluster
dataskin=crisp transparency=0.1 fillattrs=graphdata10;
colaxis valueattrs=(size=8pt weight=bold)
label='Tooth type' labelattrs=(size=18pt weight=bold);
rowaxis valueattrs=(size=14pt) label='Frequency sites'
labelattrs=(size=18pt weight=bold) grid;
format tooth tooth3_. mp mp_.;
run;
Program 3:
data myattrmap;
length linecolor $ 6 fillcolor $ 6;
input ID $ value linecolor $ fillcolor $;
datalines;
thickness 1 red red
thickness 2 green green;
run;
proc sgpanel data=freqbone2 dattrmap=myattrmap;
panelby mp /novarname headerattrs=(size=15pt)
layout=columnlattice onepanel;
vbar tooth / response=frequency
group=thickness groupdisplay=cluster
dataskin=crisp transparency=0.1 fillattrs=graphdata10;
colaxis valueattrs=(size=8pt weight=bold)
label='Tooth type' labelattrs=(size=18pt weight=bold);
rowaxis valueattrs=(size=14pt) label='Frequency sites'
labelattrs=(size=18pt weight=bold) grid;
format tooth tooth3_. mp mp_.;
run;
Hello @Jason2020.
The issue you had before was because you were using the fillattrs=graphdata10 option in the VBAR statement, and therefore that assigned the fill attributes for both of your groups as the same colour. All you need to do is remove that option to get different colours for your different groups. Were you trying to make one of the groups have a green fill colour?
proc sgpanel data=freqbone2 ;
panelby mp /novarname headerattrs=(size=15pt) layout=columnlattice onepanel;
vbar tooth / response= frequency group=thickness groupdisplay=cluster dataskin=crisp transparency=0.1;
colaxis valueattrs=(size=8pt weight=bold) label='Tooth type' labelattrs=(size=18pt weight=bold);
rowaxis valueattrs=(size=14pt) label='Frequency sites' labelattrs=(size=18pt weight=bold) grid;
format tooth tooth3_. mp mp_.;
run;
Below is an example (without using the format statement).
I forgot to mention that I am using sas 9.4 (TS1M4).
Hello @Jason2020.
The issue you had before was because you were using the fillattrs=graphdata10 option in the VBAR statement, and therefore that assigned the fill attributes for both of your groups as the same colour. All you need to do is remove that option to get different colours for your different groups. Were you trying to make one of the groups have a green fill colour?
proc sgpanel data=freqbone2 ;
panelby mp /novarname headerattrs=(size=15pt) layout=columnlattice onepanel;
vbar tooth / response= frequency group=thickness groupdisplay=cluster dataskin=crisp transparency=0.1;
colaxis valueattrs=(size=8pt weight=bold) label='Tooth type' labelattrs=(size=18pt weight=bold);
rowaxis valueattrs=(size=14pt) label='Frequency sites' labelattrs=(size=18pt weight=bold) grid;
format tooth tooth3_. mp mp_.;
run;
Below is an example (without using the format statement).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.