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

Is there a good way to create an independent legend that you can use for multiple graphs in Enterprise guide 5.1 SAS 9.2?  So that all graphs use the same color schema and the legend is only shown once?

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

David, I have presented a paper that shows you how you can plot your own legend:

http://www.lexjansen.com/pharmasug/2014/DG/PharmaSUG-2014-DG13.pdf

Otherwise, I agree with @ballardw suggestion to create a consistent legend.

View solution in original post

21 REPLIES 21
ballardw
Super User

The ability to assign graphic attributes to values across procedures was one of the major additions to SG graphics in 9.3. In 9.2 careful ordering of the categorical variables, something ensuring they appeared with a missing or 0 value depending on the procedure usually let me do this IF I pre-summarized the data. A sum of one value is that value ...

The legend issue, assuming you can get the color schema to work, might be the option NOAUTOLEGEND on the procedures where you don't want the legend to appear.

DavidPhillips2
Rhodochrosite | Level 12

This article might do the trick still playing with it.

http://support.sas.com/kb/24/945.html

djrisks
Barite | Level 11

David, I have presented a paper that shows you how you can plot your own legend:

http://www.lexjansen.com/pharmasug/2014/DG/PharmaSUG-2014-DG13.pdf

Otherwise, I agree with @ballardw suggestion to create a consistent legend.

Jay54
Meteorite | Level 14

If you really want the result as in the linked sample, and not just an independent legend, proc SGPANEL is perfectly suited for this.  It would produce a common legend, all in probably 4-5 lines of code.  Use same data set as in the sample program.  Should work with SAS 9.2.

ods graphics / reset width=5in height=3in attrpriority=color';

proc sgpanel data=one;

  panelby grp;

  series x=x y=y / group=z markers;

  run;

SeriesPanel.png

DavidPhillips2
Rhodochrosite | Level 12

In my particular case I need to charge the scale between the various graphs.  It looks like sgpanel provides one scale for multiple graphs.

Jay54
Meteorite | Level 14

You can set the UNIFORM option to get  different scaling when the axis is not shared.

Else, you can use proc SGSCATTER with PLOT statement to get fully independent plots cells.

DavidPhillips2
Rhodochrosite | Level 12

I need to include different where clauses to include different subsets of data.  Sgpannel has the group clause however it does not have the option to manually specify different subsets.

E.g. only show summation total, show all possibilities. 

I’m comparing similar graphs using line charts and bar graphs.  Sgscatter is for scatterplots.

DanH_sas
SAS Super FREQ

Actually. if you use the JOIN option on the PLOT or COMPARE statements in SGSCATTER, you can get line plots as well.

DavidPhillips2
Rhodochrosite | Level 12

Could you post a link to an example of sgscatter using a line graph without the typical scatter plots? I am using a summation clause in my current plots, the sgscatter functions appear to be for plotting data points rather than summations.  The compare feature compares two columns, I am trying to compare two different subsets using a where clause.

DanH_sas
SAS Super FREQ

Here are some simple examples:

proc means data=sashelp.class;

class age;

var weight height;

output out=temp mean=;

run;

proc sgscatter  data=temp;

plot (weight height)*age / join;

run;

proc sgscatter data=temp;

compare x=age y=(weight height) / join;

run;

DavidPhillips2
Rhodochrosite | Level 12

Can I use the same procedure to do:

Graph 1

line for the weight for age 11

line for the weight for age 12

line for the weight for age 13

Then beside it using the same legend

Graph 2

line for the weight for age 14 only including where mean > 55

line for the weight for age 15 only including where mean > 55

line for the weight for age 16 only including where mean > 55


In other words can I use where clause like functions?

DavidPhillips2
Rhodochrosite | Level 12

I’ve been working off of djrisks’ paper.  I was able to use it to create an independent series plot.  I’m currently working on adding manual sorting and coloring to the legend.  Note that the base part of the code is this:  the additional grouping is not needed for most situations.

data enroll_led;

set enroll_le;

index_final = _n_;

run;

data legend;

set enroll_led;

/* For patient legend */

do i = 6, 10;

xax = i;

output;

end;

drop i;

run;

ods graphics on / reset = all border = off imagefmt = png width = 3in height = 2in imagename

= "grlegend";

goptions reset = all;

proc template;

                define statgraph order;

                 dynamic TITLE1 TITLE2;

                 begingraph;

                 entrytitle TITLE1;

                 entrytitle TITLE2;

                layout overlay / xaxisopts =(display = NONE) yaxisopts = (display = NONE)

                y2axisopts = ( display = STANDARD reverse = true label = " "

                linearopts= ( tickvaluesequence=(start=1 end=32 increment=1)));

                /* Main plot */

                seriesplot x=xax y= degree_level / yaxis = y2 display = all group=degree_level

                index = index_final lineattrs = (pattern =1 thickness = 1) /*markerattrs = (size = 1pt)*/;

                endlayout;

                 endgraph;

                end;

                run;

                proc sgrender data= legend template=order;

                     dynamic title1=" ";

                     dynamic title2="Legend";

                run;

djrisks
Barite | Level 11

David, I'm pleased my paper helped you! For clarification, what would you like to do now?

DavidPhillips2
Rhodochrosite | Level 12

My overall goal which now is achievable given your paper, a bit of additional research, and proof of concepts; is to have a legend for a number of small dynamic dashboard graphs.  The legend needs to match the colors displayed on the graphs.  The graphs need to change display sets based on input values affecting their where clauses. The legend needs to have a predefined order that is non-alphabetical.

My plan is create a hardcoded color pattern set.

Assign the color pattern set to the legend. 

Order the legend by a database index key.

Make the legend only show the colors that are currently being used.

Sort the dataset and assign the color pattern to the dataset each time I change data subsets, when input values are changed.  (This is inefficient but appears to be the best way).

Add line charts (sgplot) and barcharts (gcharts)

I’m using SAS 9.2 and EG 5.1

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
  • 21 replies
  • 2268 views
  • 8 likes
  • 5 in conversation