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!
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.
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
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?
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.
Thanks! Using "ods html style=listing" gave me exactly what I needed!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.