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

I am using following code. i wanted legend as in the attached figure but i am getting two different leagends separately. How can i get desired legend? I am using SAS 9.3.

legend.PNGDesired legend.

 

proc means data=sashelp.class nway noprint;
    class sex age;
    var weight;
    output out=_td_mean 
                mean=mean
                lclm=low
                uclm=high;
run;

proc template;
    define statgraph highlow;
        begingraph;
            layout datapanel classvars=(sex)/columns=2
                                             columngutter=5
                                             headerlabeldisplay=value
                                             headerlabelattrs=(weight=bold)
                                             headerbackgroundcolor=lightgray
                                             columnaxisopts=(display=(label tickvalues ticks line)
                                                             label=("Age (Years)") labelattrs=(weight=bold)
                                                             linearopts=(tickvaluepriority=true tickvaluelist=(1 2 3 6 9 12)))
                                             rowaxisopts=(display=(label tickvalues ticks line)
                                                          label=("Mean Weight (kgs)") labelattrs=(weight=bold))
                                             ;
                layout prototype;
                    seriesplot x=age y=mean/group=trt01p lineattrs=(pattern=solid) name='p';
                    scatterplot x=age y=mean/group=trt01p
                             yerrorlower=low
                             yerrorupper=high
                             markerattrs=(symbol=circlefilled) name='s';
                    referenceline y=50 / LINEATTRS = (PATTERN = DOT);
                    referenceline y=150 / LINEATTRS = (PATTERN = DOT);
                endlayout;
                sidebar / align=bottom; 
                    discretelegend "s" "p" / border=false;
                  endsidebar;

            endlayout;
        endgraph;
    end;
run;
ods graphics on/noborder;
proc sgrender data=_td_mean template=highlow;
run;
ods graphics off;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Use MERGEDLEGEND.

 

proc template;
  define statgraph mergedLegend;
    begingraph;
      Layout overlay;
        scatterplot x=age y=height / group=sex name='scatter';
        seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
        mergedlegend 'scatter' 'series';
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=mergedLegend;
run;

View solution in original post

5 REPLIES 5
ballardw
Super User

Using 9.2 I get a single legend across the bottom. Adding Across=1 gets me a stacked legend at the bottom.

 

 

Rajaram
Obsidian | Level 7

legend.PNG

 

Thanks.  I tried that as well. I am getting like above.

ballardw
Super User

That sounds like the desired output. If you need different text then the LEGENDLABEL needs to be set for each of the plots.

The color and marker symbols would have to be set with the appropriate attributes for the plot.

 

Jay54
Meteorite | Level 14

Use MERGEDLEGEND.

 

proc template;
  define statgraph mergedLegend;
    begingraph;
      Layout overlay;
        scatterplot x=age y=height / group=sex name='scatter';
        seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
        mergedlegend 'scatter' 'series';
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=mergedLegend;
run;

Rajaram
Obsidian | Level 7
Thank you very much Sanjay.

I choose GTL option. Since uneven axis values not working for SGPANEL with colaxis/rowaxis but working for SGPLOT with xaxis-yaxis. I also commented your post http://blogs.sas.com/content/graphicallyspeaking/2012/04/30/axis-values-and-hint/

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
  • 5 replies
  • 1467 views
  • 1 like
  • 3 in conversation