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

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

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

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?

View solution in original post

3 REPLIES 3
AncaTilea
Pyrite | Level 9

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?

MeredithG
Calcite | Level 5

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

Jay54
Meteorite | Level 14

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 – 1 - Graphically Speaking

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 719 views
  • 0 likes
  • 3 in conversation