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

I have a dataset[attached below], and get a plot of a bunch of lines[below]. The code used does

specify the line color/thinkness. How to do so?!

Say line color in seq [RED, BLUE, CYAN, BLACK, RED, BLUE, CYAN, BLACK]

Line thickness, [1,1,1, 3,3 , 2,2,2]

 

			proc sgplot data=_t_mm_temp_coll_n_t(where=(xahead in (-20,-10,0, 5, 10,20,30,40)));
							by tvar;
							series x=ncut y= cttot/ group =xahead ;  
							yaxis max=500 min=450;
							refline  490/axis=y lineattrs=(color=red thickness=2 pattern=solid); 
							refline  480/axis=y lineattrs=(color=cyan thickness=1 pattern=solid); 
						run;quit;

 

sgplot.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Here is an example:

 

data dattrmap;
input id $ value :$20. linecolor $ linethickness;
cards;
id IBM        red     2
id Intel      green   4
id Microsoft  blue    8
;

proc sgplot data=sashelp.stocks dattrmap=dattrmap;
series x=date y=close /group=stock attrid=id;
run;

Ksharp_0-1769761144744.png

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

You can use the STYLEATTRS command.

 

Also, you can use discrete attribute maps

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n03orofvtqwhhon1kkn76l1ovjkx.htm

 

If you are concerned about getting colors and lines the way you want, then also to improve the look of your plot I suggest you use proper ENGLISH words and descriptions (or whatever language you speak normally) in titles and labels and legends, instead of computerese gibberish such as tvar=volcsum_t

--
Paige Miller
hellohere
Pyrite | Level 9

styleattrs datacontrastcolors=(lime red purple skyblue) ;  Works. But does not take linepatterns[or thinkness] anymore. 

 

The title, I will leave alone. It is generated with macro. TVar stands for Target Variable. If spell out, need many lines since of invocations with variables. 

 

 

85               proc sgplot data=_t_mm_temp_coll_n_t(where=(xahead in (0, 5, 10,20)));
86                               by tvar;
87                               styleattrs datacontrastcolors=(lime red purple skyblue) ;
88                               styleattrs DATALINEPATTERNS=(1 2 4 15);
89                               series x=ncut y= cttot/ group =xahead ;
90                               yaxis max=500 min=450;
91                               refline  490/axis=y lineattrs=(color=red thickness=2
91 ! pattern=solid);
92                               refline  480/axis=y lineattrs=(color=cyan thickness=1
92 ! pattern=solid);
93                           run;

93 !                             quit;
NOTE: PROCEDURE SGPLOT used (Total process time):
      real time           0.37 seconds
      cpu time            0.06 seconds

NOTE: This graph has ATTRPRIORITY=COLOR in effect. The cycling of your custom symbols and/or line
      patterns is based on color priority. Please see ODS Graphics documentation on ATTRPRIORITY=
      option.
NOTE: This graph has ATTRPRIORITY=COLOR in effect. The cycling of your custom symbols and/or line
      patterns is based on color priority. Please see ODS Graphics documentation on ATTRPRIORITY=
      option.
NOTE: There were 64 observations read from the data set WORK._T_MM_TEMP_COLL_N_T.
      WHERE xahead in (0, 5, 10, 20);
PaigeMiller
Diamond | Level 26

@hellohere wrote:

styleattrs datacontrastcolors=(lime red purple skyblue) ;  Works. But does not take linepatterns[or thinkness] anymore. 


That's why I also provided example of using a discrete attribute map.

 


@hellohere wrote:

 

The title, I will leave alone. It is generated with macro. TVar stands for Target Variable. If spell out, need many lines since of invocations with variables. 


In my opinion, poor choice. No one wants to see or know what your computer code looks like. They want to understand the plot. And my suggestion applies to all text on the plot, not just the title.

--
Paige Miller
Ksharp
Super User

Here is an example:

 

data dattrmap;
input id $ value :$20. linecolor $ linethickness;
cards;
id IBM        red     2
id Intel      green   4
id Microsoft  blue    8
;

proc sgplot data=sashelp.stocks dattrmap=dattrmap;
series x=date y=close /group=stock attrid=id;
run;

Ksharp_0-1769761144744.png

 

hellohere
Pyrite | Level 9

Thanks, this works out perfectly. 

 

Also can add " DATALINEPATTERNS"?! 

Ksharp
Super User
Yes. I think so. Check SAS Doc.
Ksharp
Super User

Here is an example:

data dattrmap;
input id $ value :$20. linecolor $ linethickness linepattern :$20.;
cards;
id IBM        red     2  dot
id Intel      green   4  dash
id Microsoft  blue    8  solid
;

proc sgplot data=sashelp.stocks dattrmap=dattrmap;
series x=date y=close /group=stock attrid=id;
run;

Ksharp_0-1769762692449.png

 

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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
  • 7 replies
  • 1228 views
  • 0 likes
  • 3 in conversation