%let gpath=C:\Work\Blogs\Graphically Speaking\2017\Post_46_Dec_05_Text_Position; %let dpi=200; %let w=4in; %let h=2in; ods html close; ods listing gpath="&gpath" image_dpi=&dpi; /*--Generate data--*/ data spaghetti; keep x y ylbl pos; length pos $12 ylbl $3; pi=constant("PI"); a1=10; a2=5; d1=0.2; v=1; do x=0 to 500 by 10; th=x*pi/180; y=a1*sin(th)+a2*sin(2*th+d1) +30; ylbl=''; if mod(x, 20)=0 then ylbl=put(y, 2.0); if th < 1.3 then pos='topleft'; else if th < 1.3 then pos='top'; else if th < 2.8 then pos='topright'; else if th < 5.2 then pos='bottomleft'; else if th < 5.5 then pos='bottom'; else if th < 6.3 then pos='bottomright'; else if th < 7.0 then pos='topleft'; else if th < 7.5 then pos='top'; else pos='topright'; output; end; run; /*ods html;*/ /*proc print;run;*/ /*ods html close;*/ /*--Curve with text--*/ ods graphics / reset width=&w height=&h imagename='Curve'; proc sgplot data=spaghetti noborder noautolegend; spline x=x y=y / lineattrs=(thickness=2); text x=x y=y text=ylbl / textattrs=(weight=bold); xaxis display=(noline noticks nolabel) grid; yaxis display=(noline noticks nolabel) grid; run; /*--Curve with text--*/ ods graphics / reset width=&w height=&h imagename='Curve_Pos_keyword'; proc sgplot data=spaghetti noborder noautolegend; spline x=x y=y / lineattrs=(thickness=2); text x=x y=y text=ylbl / textattrs=(weight=bold) position=top; xaxis display=(noline noticks nolabel) grid; yaxis display=(noline noticks nolabel) grid; run; /*--Curve with text at specified position-*/ ods graphics / reset width=&w height=&h imagename='Curve_Pos_Var'; proc sgplot data=spaghetti noborder noautolegend; spline x=x y=y / lineattrs=(thickness=2); text x=x y=y text=ylbl / textattrs=(weight=bold) position=pos; xaxis display=(noline noticks nolabel) grid; yaxis display=(noline noticks nolabel) grid; run;