BookmarkSubscribeRSS Feed
angeloelefante
Calcite | Level 5

Good afternoon

 

I am trying to have multiple pbslines created by sgplot.

I have succeded.

However, because of grahical presentation, I would like to have each line accompanied by a symbol (circel, squarefilled, etc) to better identify them when they are 8 lines

 

This is what I got (I also changed with combination of linepatterns, i.e not only solid)

 

SEE ATTACHMENT FOR THE FIGURE

 

 

...with this SAS syntax

 

 

title "ALL";

proc sgplot data= r5 nocycleattrs noautolegend;

styleattrs datacontrastcolors=(red blue)

datalinepatterns=(solid solid )

datasymbols=(triangle circlefilled);

pbspline y=lpwv10 x=time / group= byebye nomarkers smooth=50 nknots=5

lineattrs= (thickness=3) ;

xaxis values= (2 to 7 by 1) label= 'Time (years)';

yaxis values= (0 to 0.5 by 0.1);

 

No way to get what I am looking for

 

Any suggestion

 

Thanks in advance

Angelo S

2 REPLIES 2
ballardw
Super User

Let's see if I understand. You have turned of the autolegend so any legend created by Group values will not have a description. then you added the Nomarkers option to Pbspline so no markers are displayed.

 

Since you don't show any example of what you expect as the attachment shows an example of what the code generates, not what you want, we need some details.

 

But you want a marker. How do we know what that marker represents?

Where would it go?

 

Perhaps simplest would be to remove the NOAUTOLEGEND  then you get lines based on the current ODS Style (or overriden by the STYLEATTRS options or DATTRMAP dataset) and a legend that links the color /line pattern combinations to values of your group variable.

 

You can take one pass through sgplot to generate a data set of the elements displayed in the graph and perhaps modify that. Here is an example based on an example of Pbspline plot in the documentation.

proc sgplot data=sashelp.class
     noautolegend;
  pbspline x=height y=weight /group=sex;
  ods output sgplot=work.mysplineplot;
run;

proc sgplot data=work.mysplineplot;
  series x=PBSPLINE_HEIGHT_WEIGHT_GROUP___X 
         y=PBSPLINE_HEIGHT_WEIGHT_GROUP___Y
         /group=PBSPLINE_HEIGHT_WEIGHT_GROUP__GP
          markers
;
run;

The ODS OUTPUT creates a data set. The second is a simple example of replotting the spline as series plot.

Note that depending on YOUR data the variable names would change and the number of points in the spline part of the plot. Notice that part of this plot may look like a very fat line because of the interval between the spline resulting points is close and the markers overlap.

One way to reduce the number of markers is to add another variable to the spline plot data that will use a marker based on the group variable and plot that with a scatter plot.

data work.toplot;
   set work.mysplineplot;
   rename PBSPLINE_HEIGHT_WEIGHT_GROUP___X=splinex
          PBSPLINE_HEIGHT_WEIGHT_GROUP___Y=spliney
          PBSPLINE_HEIGHT_WEIGHT_GROUP__GP=splinegroup
   ;

   if mod(_n_,10)=5 then markery=PBSPLINE_HEIGHT_WEIGHT_GROUP___Y;
run;

proc sgplot data=work.toplot;
  series x=splinex 
         y=spliney
         /group=splinegroup
  ;
  scatter x=splinex
          y=markery
          /group=splinegroup
   ;
   label  markery='Weight'
   ;
run;
angeloelefante
Calcite | Level 5
Thanks for your reply
Thanks also for asking what I really want.
I start from this
I am not interested to have markers of individual data.
As you indicated, the interval between data is such that I get a "fat line"
I would like to have a way to identify groups by a solid line with a marker
For instance, Group 1 has a solid red line with traingel, group 2 a solid redline with filled circle, group 3 a solid blue line with diamonds, etc

I see Figure 23.38 at page 708 of the "SAS/STAT 15.2® User’s Guide
Statistical Graphics Using ODS" indicating that my desired style is part of the Default language
However, I am not able to get those lines

Thanks
Angelo

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 395 views
  • 2 likes
  • 2 in conversation