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:
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.
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
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
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;
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.