BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jason2020
Obsidian | Level 7

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.

 

Jason2020_0-1628915763742.jpeg

 

 

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;

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

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

SAS groups.png

 

View solution in original post

4 REPLIES 4
Jason2020
Obsidian | Level 7

I forgot to mention that I am using  sas 9.4 (TS1M4).

djrisks
Barite | Level 11

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

SAS groups.png

 

Jason2020
Obsidian | Level 7
Great. Thank you very much.
I spent hours trying to find a solution. Thanks again.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1049 views
  • 4 likes
  • 2 in conversation