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

I have the following

      seriesplot  x=eval(atptn-13*&offx) y=mean1 /   lineattrs=graphdata1(color=blue pattern=shortdash thickness=2) name='series1' legendlabel="Drug A";

      scatterplot x=eval(atptn-13*&offx) y=mean1/     YErrorUpper=High1 YErrorLower=Low1

                  markerattrs=graphdata1(color=blue symbol=trianglefilled size=9) errorbarattrs=graphdata1(color=blue pattern=solid)

                  name='scatter1' legendlabel="Drug A";

      seriesplot  x=eval(atptn-11*&offx) y=mean2 /   lineattrs=graphdata2(color=red pattern=mediumdash  thickness=2) name='series2' legendlabel="Drug B";

      scatterplot x=eval(atptn-11*&offx) y=mean2 /    YErrorUpper=High2 YErrorLower=Low2

                  markerattrs=graphdata2(color=red symbol=starfilled size=9) errorbarattrs=graphdata2(color=red pattern=solid)

                  name='scatter2' legendlabel="Drug B";

How do I use Mergedlegend statement for the above case

Currently Im using it in a following way

mergedlegend 'series1' 'scatter1' 'series2' 'scatter2' / across=1 location=inside halign=right valign=top;

But it is not working !!

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

You can certainly place multiple legends in a Layout Gridded  or Lattice, one each with the two associated Scatter and Series plots.   With SAS 9.4, you can use a Layout GlobelLegend within which you can place the individual MergedLegends.  Use AutoAlign or HAlign and VAlign.

Layout Overlay;

  SeriesPlot...;

  Scatterplot...;

  SeriesPlot...;

  Scatterplot...;

  Layout Gridded / halign=   valign= ;

    mergedlegend 'series1' 'scatter1' / <options>;

    mergedlegend 'series2' 'scatter2' / <options>;

  endlayout;

endlayout;

View solution in original post

5 REPLIES 5
Jay54
Meteorite | Level 14

For MergedLegend, you can use only 2 statement names as required parameters.  See Doc:

"The MERGEDLEGEND statement can be used to consolidate legend entries when the graph displays grouped data for two plots. The statement must specify exactly two names that reference the source for the legend entry values."

SASSLICK001
Obsidian | Level 7

Thanks Sanjay for your reply, Yes I have seen this in the documentation! In that case, this is a kind of limitation for MERGEDLEGEND! Is there any other way I can achieve this?

Jay54
Meteorite | Level 14

You can certainly place multiple legends in a Layout Gridded  or Lattice, one each with the two associated Scatter and Series plots.   With SAS 9.4, you can use a Layout GlobelLegend within which you can place the individual MergedLegends.  Use AutoAlign or HAlign and VAlign.

Layout Overlay;

  SeriesPlot...;

  Scatterplot...;

  SeriesPlot...;

  Scatterplot...;

  Layout Gridded / halign=   valign= ;

    mergedlegend 'series1' 'scatter1' / <options>;

    mergedlegend 'series2' 'scatter2' / <options>;

  endlayout;

endlayout;

SASSLICK001
Obsidian | Level 7

Thanks you so much Sanjay this is very helpful and I've seen layout globallegend but not gridded which plots outside the graph!

Anyway this works to me !! Thanks!!!

Jay54
Meteorite | Level 14

You can nest a Layout Gridded inside the Layout Overlay (like I showed earlier) if you want to place the legend inside the data area.  Or you can place it outside using Layout GlobelLegend, or Gridded or Lattice.  It depends on how you structure your template.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1777 views
  • 6 likes
  • 2 in conversation