BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

Hello,

 

I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:

 

here is the dataset I have:

treatment_group

scale

percent

drug

0

.

drug

1

2.5

drug

2

2.5

drug

3

12.5

drug

4

24.2

drug

5

23.3

drug

6

9.2

drug

7

25.8

control

0

.

control

1

0.4

control

2

6.0

control

3

12.0

control

4

25.7

control

5

24.1

control

6

12.4

control

7

19.3

 

I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.

 

proc sgplot data=a.FreqOut;

 

vbar treatment_group/ response=Percent group=scale groupdisplay=stack;

xaxis discreteorder=data;

yaxis grid values=(0 to 100 by 10) label="Percentage of Total";

run;

 

Also for Each scale, I would like to give a RGB color

For examples

- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366

- Scale 5 should have certain color=cxffffcc

 

I tried but no luck!

pattern1 v=solid color=cx9999ff; 
pattern2 v=solid color=cx993366; 
pattern3 v=solid color=cxffffcc; 

 

Any help would be appreciated!!

2 REPLIES 2
radhikaa4
Calcite | Level 5

Hello,

 

I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:

 

here is the dataset I have:

treatment_group

scale

percent

drug

0

.

drug

1

2.5

drug

2

2.5

drug

3

12.5

drug

4

24.2

drug

5

23.3

drug

6

9.2

drug

7

25.8

control

0

.

control

1

0.4

control

2

6.0

control

3

12.0

control

4

25.7

control

5

24.1

control

6

12.4

control

7

19.3

 

I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.

 

proc sgplot data=a.FreqOut;

 

vbar treatment_group/ response=Percent group=scale groupdisplay=stack;

xaxis discreteorder=data;

yaxis grid values=(0 to 100 by 10) label="Percentage of Total";

run;

 

Also for Each scale, I would like to give a RGB color

For examples

- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366

- Scale 5 should have certain color=cxffffcc

 

I tried but no luck!

pattern1 v=solid color=cx9999ff; 
pattern2 v=solid color=cx993366; 
pattern3 v=solid color=cxffffcc; 

 

Any help would be appreciated!!

Reeza
Super User

You posted this in SAS VA, are you using SAS Visual Analytics, which is a GUI interface or programming in Base?

 

Assuming you're using Base - Pattern statements apply to SAS/GRAPH not SGPLOT. You can use the STYLEATTRS() to control the colour. You may want a data attribute map, but try adding the following statement after your SGPLOT statement, but before your VBAR statement. 

 

styleattrs datacolors=(cx9999ff cs993366 cxffffcc);

@radhikaa4 wrote:

Hello,

 

I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:

 

here is the dataset I have:

treatment_group

scale

percent

drug

0

.

drug

1

2.5

drug

2

2.5

drug

3

12.5

drug

4

24.2

drug

5

23.3

drug

6

9.2

drug

7

25.8

control

0

.

control

1

0.4

control

2

6.0

control

3

12.0

control

4

25.7

control

5

24.1

control

6

12.4

control

7

19.3

 

I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.

 

proc sgplot data=a.FreqOut;

 

vbar treatment_group/ response=Percent group=scale groupdisplay=stack;

xaxis discreteorder=data;

yaxis grid values=(0 to 100 by 10) label="Percentage of Total";

run;

 

Also for Each scale, I would like to give a RGB color

For examples

- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366

- Scale 5 should have certain color=cxffffcc

 

I tried but no luck!

pattern1 v=solid color=cx9999ff; 
pattern2 v=solid color=cx993366; 
pattern3 v=solid color=cxffffcc; 

 

Any help would be appreciated!!




sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2001 views
  • 0 likes
  • 2 in conversation