Data visualization with SAS programming

proc sgplot common legend

Reply
Contributor
Posts: 24

proc sgplot common legend

Hi All,

             Using the below link I have created created multiple sgplot output on to one pdf . What I need is to create a common legend . I have tried creating a blank sgplot with legend by making the graph axis values out of range but it didn't worked as it is masking the entire multiple sgplot output. Is there any other way to do it.

41461 - Put multiple PROC SGPLOT outputs on the same PDF page using PROC GREPLAY

Thanks,

Sundeep.

SAS Super FREQ
Posts: 864

Re: proc sgplot common legend

You can put multiple SG outputs on the same PDF page without using GREPLAY. In fact, if you use GREPLAY to do it, you would need to be very careful how you generated the images as to not create image artifacts when putting them into PDF. To help with both this issue and the common legend, it would be helpful to know the types of graphs you're generating, as there might be a simple way to get both to happen is certain situations.

Contributor
Posts: 24

Re: proc sgplot common legend

Hi Dan ,

                   Thanks for the quick response I am generating a barline chart . I used greplay as I need to create a 3* 3 graph template.

Thanks,

Sundeep.

SAS Super FREQ
Posts: 864

Re: proc sgplot common legend

Okay, two more questions:

1. What version of SAS are you using?

2. Are you generating these bar-line charts using a BY-group?

Contributor
Posts: 24

Re: proc sgplot common legend

Hi Dan,

                   I am using SAS 9.4 and I am not using by variable but group option in the vbarparm.I am not using vbar and vline as I need different group labels.

sample code

proc sgplot data=&inpt.;

where tr= "&FRT.";

vbarparm category=var1 response=cnt / group=grp1 name="a";

series x=var1  y=rt / group=grp2 y2axis name="b";

keylegend "a" "b"  / across=4;

run;

Thanks,

Sundeep.

SAS Super FREQ
Posts: 864

Re: proc sgplot common legend

Thanks for the code sample. That really helps. Here is a solution that should give you a 3x3 grid of charts with a common legend on each PDF page. The output is assuming some relationship between each plot:

ods pdf file="temp.pdf";

ods graphics / width=7in height=9.5in; /* allowing for some margins */

proc sgpanel data=&inpt.;

panelby tr / novarname onepanel rows=3 columns=3;

vbarparm category=var1 response=cnt / group=grp1 name="a";

series x=var1  y=rt / group=grp2 y2axis name="b";

keylegend "a" "b"  / across=4;

run;

ods pdf close;

If you do not want the headers, add the NOHEADER option to the PANELBY statement. Give that a try and see if that will work for you.

Contributor
Posts: 24

Re: proc sgplot common legend

Thanks Dan for the code sample I will try that and get back to you .

Contributor
Posts: 24

Re: proc sgplot common legend

Hi Dan,

                 Sgpanel doesn't support  y2axis I am getting error at series statement?

Thanks,

Sundeep.

Post a Question
Discussion Stats
  • 7 replies
  • 574 views
  • 0 likes
  • 2 in conversation