Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcmaxwell
Fluorite | Level 6

Hello, 

I am making a simple bar graph (2 bars) and I would like each bar to be a different color. Below is the code I used to make the data set and the graph. 

data new;      
	length cPLTL $9 ;  
	input percent cPLTL @@;      
cards;      
2.19 cPLTL      
17.03 non-cPLTL       
;          
proc print data=new; run;    
   
proc sgplot data=new;        
	styleattrs datacolors=(cx66FF66 cxFF6666); 
	vbar cPLTL / response=percent groupdisplay=cluster barwidth=.4; 
	yaxis label="Percent of unsuccessful students";       
	xaxis display=(nolabel);              
	run;     

My issue is that the styleattrs command is not working. Can someone please show me what I am doing wrong? I would like to use the color naming system values to specify navy blue and bright orange, but I am aware that the colors in the code above don't specify that. I would also be open to learning a simpler way of assigning colors. 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@mcmaxwell wrote:

Hello, 

I am making a simple bar graph (2 bars) and I would like each bar to be a different color. Below is the code I used to make the data set and the graph. 

data new;      
	length cPLTL $9 ;  
	input percent cPLTL @@;      
cards;      
2.19 cPLTL      
17.03 non-cPLTL       
;          
proc print data=new; run;    
   
proc sgplot data=new;        
	styleattrs datacolors=(cx66FF66 cxFF6666); 
	vbar cPLTL / response=percent groupdisplay=cluster barwidth=.4; 
	yaxis label="Percent of unsuccessful students";       
	xaxis display=(nolabel);              
	run;     

My issue is that the styleattrs command is not working. Can someone please show me what I am doing wrong? I would like to use the color naming system values to specify navy blue and bright orange, but I am aware that the colors in the code above don't specify that. I would also be open to learning a simpler way of assigning colors. 

Thanks!


GROUPDISPLAY without a GROUP variable is hint as to what is not happening.

 

Add GROUP= cPLTL to the VBAR options to make each bar with a different color. 

Had nothing to do with the STYLEATTRS but missing group.

 

View solution in original post

1 REPLY 1
ballardw
Super User

@mcmaxwell wrote:

Hello, 

I am making a simple bar graph (2 bars) and I would like each bar to be a different color. Below is the code I used to make the data set and the graph. 

data new;      
	length cPLTL $9 ;  
	input percent cPLTL @@;      
cards;      
2.19 cPLTL      
17.03 non-cPLTL       
;          
proc print data=new; run;    
   
proc sgplot data=new;        
	styleattrs datacolors=(cx66FF66 cxFF6666); 
	vbar cPLTL / response=percent groupdisplay=cluster barwidth=.4; 
	yaxis label="Percent of unsuccessful students";       
	xaxis display=(nolabel);              
	run;     

My issue is that the styleattrs command is not working. Can someone please show me what I am doing wrong? I would like to use the color naming system values to specify navy blue and bright orange, but I am aware that the colors in the code above don't specify that. I would also be open to learning a simpler way of assigning colors. 

Thanks!


GROUPDISPLAY without a GROUP variable is hint as to what is not happening.

 

Add GROUP= cPLTL to the VBAR options to make each bar with a different color. 

Had nothing to do with the STYLEATTRS but missing group.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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