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

Hello,

I am trying to create a graph using proc sgplot and the loess function. Here is the code that I am using:

proc sgplot data=bmipred;

  format BMIgrp BMIgrpfmt.;

  loess x=t y=pred/smooth=0.4 group=BMIgrp nomarkers lineattrs= (thickness=2);

  keylegend / title="BMI Category";

  yaxis label='Diastolic Blood Pressure' grid values = (0 to 200 by 20);

  xaxis label='Time' grid values = (0 to 50 by 10);

run;

The problem I am running into is the "lineattrs" option. Since I am using the group option "group=BMIgrp", it will produce three lines for each of the BMI categories I am using. Unfortunately, it produces the same solid line pattern, with different colors, for each BMI category. Is there a way for me to specify that each BMI category line should have a different line pattern? For instance, is there a way for the Normal weight category to have a dash line, the Obese to have a solid line, and the Overweight category to have a dash dash line?

I thought if didn't include a 'pattern=' within the lineattrs option that it would produce three different line patterns for each BMI category, but it does not. Could someone please help me! Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

You are likely using SAS 9.3 with HTML output.  In this case, the default style is HTMLBlue that is a "COLOR" priority style which only rotates the colors first.   If you just want different patterns for each group (and don't care what they are), set STYLE=LISTING on the HTML destination.  The LISTING style does not have COLOR priority, and will rotate both color and linepatterns (or symbols) for each group.

If you want to assign specific line patterns for the group values, use the DATTRMAP feature as suggested by PGStats.

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

If using SAS version 9.3, you could use an attribute map dataset to define the visual attributes for each group.

With previous SAS versions you have to modify the graphic style template, more specifically, the graphdata1-graphdatan style elements. Have a look at the modstyle style template modification macro, it can save you a lot of time. - PG

PG
AncaTilea
Pyrite | Level 9

Hi.

What happens if you take the format statement out.

I ran your code (using SASHELP.class)

and attached is what I got:

proc sgplot data=sashelp.class;

  loess x=age y=height/smooth=0.4 group=sex nomarkers lineattrs= (thickness=2);

  keylegend / title="Sex Category";

  yaxis label='Height' grid values = (30 to 100 by 20);

  xaxis label='Age' grid values = (10 to 15 by 1);

run;

Is this sort of what you want?


SGPlot3.png
Jay54
Meteorite | Level 14

You are likely using SAS 9.3 with HTML output.  In this case, the default style is HTMLBlue that is a "COLOR" priority style which only rotates the colors first.   If you just want different patterns for each group (and don't care what they are), set STYLE=LISTING on the HTML destination.  The LISTING style does not have COLOR priority, and will rotate both color and linepatterns (or symbols) for each group.

If you want to assign specific line patterns for the group values, use the DATTRMAP feature as suggested by PGStats.

kelly6984
Fluorite | Level 6

Thanks! Using "ods html style=listing" gave me exactly what I needed!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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