BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASAlex101
Quartz | Level 8

I'm using EG. I have some code that produces a bar chart: 

data work.plot1;
length Month $20.;
infile datalines delimiter='#';
input Year MOnthNum Month $ S DL cum_sum;
datalines;
2021#1#January#672106#672#672106
2021#2#February#365000#365#1037106
2021#3#March#5155529#5156#6192635.49
2021#4#April#4503598#4504#10696232.99
2021#5#May#3290652#3291#13986884.99
2021#6#June#5223191#5223#19210076.24
2021#7#July#3352705#3353#22562781.24
2021#8#August#2019160#2019#24581941.24
2021#9#September#765000#765#25346941.24
2021#10#October#3376000#3376#28722941.24
2021#11#November#3155655#3156#31878596.24
2022#2#February#4622274#4622#4622274.1
2022#3#March#6871150#6871#11493424.1
2022#4#April#1154663#1155#12648087.1
2022#5#May#2281975#2282#14930062.38
2022#6#June#1734715#1735#16664777.38
2022#7#July#2804008#2804#19468785.13
2022#8#August#3110594#3111#22579379.13
2022#9#September#3767519#3768#26346898.23
2022#10#October#4114789#4115#30461686.95
2022#11#November#1309455#1309#31771141.95
;
run;
data WORK.AxisLabelsOrder;
LENGTH Month $100.;
Input  Month $;
datalines;
January
February
March
April
May
June
July
August
September
October
November
December
;
run;
Proc SQL noprint;
Select "'"||STRIP(Month)||"'" into:xaxis SEPARATED BY ' ' 
FROM WORK.AxisLabelsOrder;
quit;
proc sgplot data=WORK.Plot1; 
vbar Month  /
response = cum_sum 
stat=sum 
group=Year 
DATALABELFITPOLICY=NONE 
datalabel=DL 
datalabelattrs=(size=7px) 
groupdisplay=cluster
barwidth=0.90
GROUPORDER=ASCENDING;

yaxis 
valuesformat=COMMA10. 
display=(nolabel) ;
keylegend / title="";
XAXISTABLE;

xaxis 
values=( &xaxis.)
DISPLAY=(NOLABEL);
run;

I want to be able to change the bar colors for each group. for instance for 2021 I want to be grey and 2022 I want to be light blue. I can't seem to make this work. 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

proc sgplot data=WORK.Plot1; 

styleattrs datacolors=(grey lightblue);   /*<-----*/

vbar Month  /  nooutline    /*<-----*/
response = cum_sum 
stat=sum 
group=Year 
DATALABELFITPOLICY=NONE 
datalabel=DL 
datalabelattrs=(size=7px) 
groupdisplay=cluster
barwidth=0.90
GROUPORDER=ASCENDING;

yaxis 
valuesformat=COMMA10. 
display=(nolabel) ;
keylegend / title="";
XAXISTABLE;

xaxis 
values=( &xaxis.)
DISPLAY=(NOLABEL);
run;

Ksharp_0-1674128693037.png

 

View solution in original post

1 REPLY 1
Ksharp
Super User

proc sgplot data=WORK.Plot1; 

styleattrs datacolors=(grey lightblue);   /*<-----*/

vbar Month  /  nooutline    /*<-----*/
response = cum_sum 
stat=sum 
group=Year 
DATALABELFITPOLICY=NONE 
datalabel=DL 
datalabelattrs=(size=7px) 
groupdisplay=cluster
barwidth=0.90
GROUPORDER=ASCENDING;

yaxis 
valuesformat=COMMA10. 
display=(nolabel) ;
keylegend / title="";
XAXISTABLE;

xaxis 
values=( &xaxis.)
DISPLAY=(NOLABEL);
run;

Ksharp_0-1674128693037.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 1017 views
  • 0 likes
  • 2 in conversation