Data visualization with SAS programming

Proc SGPLOT

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc SGPLOT

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!


Accepted Solutions
Solution
‎06-18-2013 02:46 PM
SAS Super FREQ
Posts: 1,148

Re: Proc SGPLOT

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


All Replies
Respected Advisor
Posts: 4,826

Re: Proc SGPLOT

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
Super Contributor
Posts: 543

Re: Proc SGPLOT

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
Solution
‎06-18-2013 02:46 PM
SAS Super FREQ
Posts: 1,148

Re: Proc SGPLOT

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.

Occasional Contributor
Posts: 15

Re: Proc SGPLOT

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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