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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1098 views
  • 6 likes
  • 4 in conversation