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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.