Hi All
I am trying to draw graphs using the proc sgplot with the group option. SAS provides me with automatic colours and I need to choose my own preferred colours. the program I use is as below and data attached.
Hi @mmohotsi,
A simple solution is to add a STYLEATTRS statement to the PROC SGPLOT step and to specify the group colors in the DATACONTRASTCOLORS= option.
Example:
proc sgplot data=Tested3; styleattrs datacontrastcolors=(lime gray purple skyblue); vline Dates / response=Amount group=sampling_point groupdisplay=overlay ; ...
See Color-Naming Schemes for the various ways to specify colors (e.g., by RGB values).
For which elements of your graph do you want to specify colors?
Hi @mmohotsi,
A simple solution is to add a STYLEATTRS statement to the PROC SGPLOT step and to specify the group colors in the DATACONTRASTCOLORS= option.
Example:
proc sgplot data=Tested3; styleattrs datacontrastcolors=(lime gray purple skyblue); vline Dates / response=Amount group=sampling_point groupdisplay=overlay ; ...
See Color-Naming Schemes for the various ways to specify colors (e.g., by RGB values).
Good day
Solution accepted
Thanks to you FreelanceReinh Jade
Much appreciated
If you want graphs to display the same properties, colors, markers, line types for example based on the VALUE of a group variable then you likely want to investigate the use of DATTRMAP= helper data set.
Other approaches using the same style lists can display the same value with different colors based on the order of the data.
Here is an example to demonstrate the order of values encountered can affect the color usage:
data work.class; set sashelp.class; run; proc sort data=work.class; by sex; run; proc sgplot data=work.class; title "Sorted by Sex"; styleattrs datacontrastcolors=(Red blue); scatter x=height y=weight/group=sex; run;title; proc sort data=work.class; by descending sex; run; proc sgplot data=work.class; title "Sorted by descending Sex"; styleattrs datacontrastcolors=(Red blue); scatter x=height y=weight/group=sex; run;title;
@mmohotsi wrote:
Hi All
I am trying to draw graphs using the proc sgplot with the group option. SAS provides me with automatic colours and I need to choose my own preferred colours. the program I use is as below and data attached.
proc sgplot data=Tested3;vline Dates / response=Amount group=sampling_point groupdisplay=overlay ;yaxis values=(0 to 3000 by 30000) label='Free Chlorine' grid LABELATTRS=(weight=bold family=Helvetica size=7)VALUEATTRS=(family=Helvetica size=7 style=normal weight=normal ) ;refline 9500 / axis=y label=('9500 expected') lineattrs=(color=red pattern=dash) labelattrs=(size=7) labelloc=inside;xaxis interval=day VALUESROTATE=VERTICAL label='Sampled dates' LABELATTRS=(weight=bold size=7) valuesrotate=verticalVALUEATTRS=(family=arial size=10 style=normal weight=normal ) type=time;title1 j=c "Expenditure trend" bold;run;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.