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

Hello,

 

I am using the following code:

 

ods graphics on;
proc sgplot data=numbers noautolegend;
series x=time y=rate / group=group_cat;
keylegend / title='Group Categories' position=right;
xaxis grid label="Week";
yaxis grid;
run;
ods graphics off;

 

and the plot I get is below:

PLOT.JPG

I need help with changing the patterns, thickness and colors of each line in this plot. The variable group_cat has 4 categories. Is it possible to do it within this code or do I need to create 4 variables representing the 4 categories and add 4 series statements? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can use the STYLEATTRS command with the DATACONTRASTCOLORS= option in PROC SGPLOT.

 

Or you can also assign colors via a discrete attribute map: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You can use the STYLEATTRS command with the DATACONTRASTCOLORS= option in PROC SGPLOT.

 

Or you can also assign colors via a discrete attribute map: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm

--
Paige Miller
Novice_
Fluorite | Level 6
Thank you so much.
Both options work. I tried both and found that the datacontrastcolors gives less control compared to the other one.
Best Regards
Ksharp
Super User
data dattrmap;
retain ID "myid";
input value :$20. linethickness  linecolor $ linepattern $;
datalines;
IBM    2  orange  solid
Intel    4    blue    dot
Microsoft  8    red    longdash
;
run;


proc sgplot data=sashelp.stocks dattrmap=dattrmap;
where date between '01JAN02'd and '30DEC02'd;
series x=date y=close/group=stock attrid=myid;
run;
 
 

 

 
Novice_
Fluorite | Level 6

Thank you.

 

I have incorporated your code as following:

 

data dattrmap;
retain ID "myid";
INPUT value :$20. linethickness linecolor $ linepattern $;
datalines;
One 2 red soild
TWO 2 red dash
THREE 2 blue solid
FOUR 2 blue dash
;
run;
ods graphics on;
proc sgplot data=numbers dattrmap=dattrmap;
where time between 0 and 53;
series x=time y=rate / group=group_cat attrid=myid;
keylegend / title='Group Categories' position=right;
xaxis grid label="Week";
yaxis grid;
run;
ods graphics off;

 

However, this gives me an error: ERROR 772-580: Syntax error: expecting a constant or a dynamic.

 

Novice_
Fluorite | Level 6
I think I got it. Perhaps I should have added the ID in the input statement.
Thanks a lot.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1170 views
  • 0 likes
  • 3 in conversation