SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mmohotsi
Obsidian | Level 7

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=vertical   
VALUEATTRS=(family=arial size=10 style=normal weight=normal ) type=time;
title1 j=c "Expenditure trend" bold;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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).

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

For which elements of your graph do you want to specify colors?

mmohotsi
Obsidian | Level 7
Good morning

I wish to draw trend line for amount and group by sampling_point with Dates on the horizontal axis
FreelanceReinh
Jade | Level 19

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).

mmohotsi
Obsidian | Level 7
Thank you FreelanceReinh (Jade | Level 19)
That's the solution to my problem

Regards

mmohotsi
Obsidian | Level 7

Good day

 

Solution accepted

 

Thanks to you FreelanceReinh Jade

 

Much appreciated

ballardw
Super User

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=vertical   
VALUEATTRS=(family=arial size=10 style=normal weight=normal ) type=time;
title1 j=c "Expenditure trend" bold;
run;

 

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 6 replies
  • 1088 views
  • 3 likes
  • 4 in conversation