## VBARs of different colors

Solved
Occasional Contributor
Posts: 12

# VBARs of different colors

Hi all,

I have a bar graph with a 6-level categorical variable (SLNLOS) and the investigator wants three of the bars to be one color and three bars to be another color. I'm not great at template modification and I can't think of how I would change the color of three levels of the variable since it's rather arbitrary.

It may be pertinent that it has to be a 600 DPI .tiff per the journal requirements.

Code:

ods listing image_dpi=600;

ods graphics on/ imagefmt=tiff imagename="Final Figure 2";

proc sgplot data=long;

vbar slnlos/response=inp stat=mean;

run;

Thanks!

Meredith

Accepted Solutions
Solution
‎04-16-2013 09:57 AM
Super Contributor
Posts: 543

## Re: VBARs of different colors

Hi Meredith,

I believe you will need to "assign" a group to inp variable, such that if inp is one of the three bars value then grp = 1, else grp = 0;

then you could use this code:

proc template;

define statgraph my_design;

begingraph;

layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;

layout overlay;

barchart x=slnlos y=inp/ group=GRP name='bar' clusterwidth=1.0;

endlayout;

endlayout;

endgraph;

end;

run;

proc sgrender data=WORK.long template=my_design;

run;

Does this make sense?

All Replies
Solution
‎04-16-2013 09:57 AM
Super Contributor
Posts: 543

## Re: VBARs of different colors

Hi Meredith,

I believe you will need to "assign" a group to inp variable, such that if inp is one of the three bars value then grp = 1, else grp = 0;

then you could use this code:

proc template;

define statgraph my_design;

begingraph;

layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;

layout overlay;

barchart x=slnlos y=inp/ group=GRP name='bar' clusterwidth=1.0;

endlayout;

endlayout;

endgraph;

end;

run;

proc sgrender data=WORK.long template=my_design;

run;

Does this make sense?

Occasional Contributor
Posts: 12

## Re: VBARs of different colors

Awesome, thank you! I really need to sit down and spend some time figuring out template modification... ugh...

SAS Super FREQ
Posts: 1,210

## Re: VBARs of different colors

You can do this with proc SGPLOT too:

vbar slnlos / response=inp stat=mean group=grp;

If you have SAS 9.3, you can use the DATTRMAP to do this.  Set GRP=slnlos, and then defining an attribues map with specific colors for each category value.  See:  Attribute Maps &#8211; 1 - Graphically Speaking

🔒 This topic is solved and locked.