BookmarkSubscribeRSS Feed
TimurShangareev
Calcite | Level 5

I try to create template for 

PROC SGRENDER DATA=INDS TEMPLATE=myTemplate;

I want to rotate legend (by Default it Horizontal in any position),  but can't find option.

I found ODS LEGEND, but it seems like it's working for PROC GPLOT. 

Is there exist such option or another method to rotate legend in SGRENDER? 

 

4 REPLIES 4
JeffMeyers
Barite | Level 11
Can you clarify? You want the text running vertically or you want the items in the legend to be in rows instead of columns?
TimurShangareev
Calcite | Level 5

I want to set text vertically

JeffMeyers
Barite | Level 11
To my knowledge there is no default option to build a legend vertically. It would require you to manually make it using something like a layout gridded combined with Entry statements (which have a rotate option) with legend items that match your graph. You would have to set the valueattrs to be size 1 and white to hide the normal legend text. This would be more complicated if not doing a bar or scatter plot as a line legend for series would also not be rotated and you would have to use annotation (drawline) to do so. If I have free time later I can make an example.
Ksharp
Super User

I did not see an option you could do that either.

The workaround way I could image is using PROC SGPLOT to make a picture for LEGEND and insert this picture into PROC SGRENDER by rotating it 90 degree.

But that would cost you a lot of time and you need to make legend be consistent with original graph.

Here is an example:

 


%let path=%sysfunc(pathname(work));  *the path stored the picture ;




*Make a picture for Legend;
data x;
input label $ x y s_male_x s_male_y male $ male_x male_y s_female_x s_female_y female $  female_x female_y;
cards;
SEX      0 0  1 0  Male   1.5  0   2.5  0  Female   3.2 0
;
run;
title;
ods listing gpath="&path." style=htmlblue image_dpi=300;
ods graphics/width=250px height=40px reset=index imagename='legend' outputfmt=png noborder;
proc sgplot data=x noautolegend pad=0; *noborder;
scatter x=x y=y/markerchar=label markercharattrs=(size=20);

scatter x=s_male_x y=s_male_y/markerattrs=graphdata1(symbol=squarefilled size=20);
scatter x=male_x y=male_y/markerchar=male markercharattrs=(size=20);

scatter x=s_female_x y=s_female_y/markerattrs=graphdata2(symbol=squarefilled size=20);
scatter x=female_x y=female_y/markerchar=female markercharattrs=(size=20);

xaxis display=none;
yaxis display=none;
run;




%sganno
data sganno;
 %SGIMAGE(
     IMAGE="&path.\legend1.png",
     ANCHOR="CENTER" ,
	 IMAGESCALE="FITHEIGHT",
	 ROTATE=90,
	 HEIGHT=10,
     HEIGHTUNIT= "PERCENT",
     LAYER="FRONT",

     DRAWSPACE="WALLPERCENT",
     X1=5,
     Y1=65,ID="BAR"
     )
run;


proc template;
define statgraph y2axis;
begingraph;

layout overlay   ;
barchart category=age response=weight/group=sex groupdisplay=cluster ;
annotate / id="BAR";
endlayout;

endgraph;
end;
run;
ods graphics/reset=all;
proc sgrender data=sashelp.class template=y2axis sganno=sganno;
run;

Ksharp_0-1755677861345.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 303 views
  • 0 likes
  • 3 in conversation