Data visualization with SAS programming

SGPlot YAXISTABLE greater than or equal symbol

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

SGPlot YAXISTABLE greater than or equal symbol

Hello,

 

I would like to include a greater than or equals to symbol in a YAXISTABLE in SGPlot. I am trying all the usual unicode tricks but it doesn't seem to work. I am running 9.4TS1M3 windows 64-bit. Sample code below.

 

data table;
length area $30. diag $100.;
set data;

...

if test='2step' then diag="2-step RPG/POC HbA1c (*ESC*){unicode '2265'x} 6.5%";
if test='POC' then diag="POC HbA1c (*ESC*){unicode '2265'x} 6.5%";
if test='TAN' then diag="Full TANDEM score (*ESC*){unicode '2265'x} 14.1";
if test='RPG' then diag="RPG (*ESC*){unicode '2265'x} 11.1 mmol/l";

...

label diag="Diagnostic test" area="AUROC (95% CI)";

run;

 

ods listing gpath="..." image_dpi=300 style=tfl;
ods graphics / imagename="Diagnostics forest plot" reset=index height=9in width=8in;

proc sgplot data=table nowall noborder noautolegend;
styleattrs axisextent=data;
scatter y=y_val x=sen / markerattrs=(symbol=squarefilled size=4);
highlow y=y_val low=sen_l high=sen_u;

yaxistable diag / label location=inside position=left labelattrs=(size=7) valueattrs=(size=6);
yaxistable area / label location=inside position=left labelattrs=(size=7) valueattrs=(size=6);

xaxis display=(nolabel) values=(0 to 100 by 10);
yaxis reverse display=none;

run;

 

 

I have been able to include these symbols in SGPlot titles and legends, but this is the first time I've attempted to include it in a YAXISTABLE. Is there something I'm missing?

 

Thanks,

 

Daniel


Accepted Solutions
Solution
a week ago
SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

[ Edited ]

https://www.pharmasug.org/proceedings/2017/QT/PharmaSUG-2017-QT15.pdf

 

You have to either use a format or SG annotation.  This paper shows one way that I have done it.  I though some of our blogs in Graphically Speaking probably show other ways (but I'm not finding one). https://blogs.sas.com/content/graphicallyspeaking/

 

This new blog (insplired by your question) makes it easy to insert a number of special characters into axis tables.

 

https://blogs.sas.com/content/graphicallyspeaking/2017/10/09/advanced-ods-graphics-axis-tables-conta...

 

Here are two simple illustrations using formats.

 

data x;
   input age;
   n = _n_;
   datalines;
1
2
3
;

proc format;
   value agefmt 1 = 'Age'
                2 = "< 12"
                3 = "(*ESC*){Unicode '2265'x} 12";
run;


ods html body='b.html image_dpi=300';
ods graphics on / width=2in height=1.5in;
proc sgplot data=x;
   yaxistable age / position=left nolabel valuejustify=left;
   hbar n / barwidth=0.3;
   format age agefmt.;
   yaxis display=none;
   xaxis display=none;
   run;
ods html close;

data x2;
   input age $ 1-8;
   AxisVar = _n_;
   datalines;
Age
< 12
>= 12
;

data cntlin(keep=type fmtname start label);
   set x2;
   Type    = 'n';
   FmtName = "NewAgeFmt";
   Start   = axisvar;
   Label   = tranwrd(age, '>=', "(*ESC*){Unicode '2265'x}"); 
run;   

proc format cntlin=cntlin; quit;

ods html body='b.html image_dpi=300';
ods graphics on / width=2in height=1.5in;
proc sgplot data=x2;
   yaxistable axisvar / position=left nolabel valuejustify=left;
   hbar axisvar / barwidth=0.3;
   format axisvar newagefmt.;
   yaxis display=none;
   xaxis display=none;
   run;
ods html close;

 

View solution in original post


All Replies
Solution
a week ago
SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

[ Edited ]

https://www.pharmasug.org/proceedings/2017/QT/PharmaSUG-2017-QT15.pdf

 

You have to either use a format or SG annotation.  This paper shows one way that I have done it.  I though some of our blogs in Graphically Speaking probably show other ways (but I'm not finding one). https://blogs.sas.com/content/graphicallyspeaking/

 

This new blog (insplired by your question) makes it easy to insert a number of special characters into axis tables.

 

https://blogs.sas.com/content/graphicallyspeaking/2017/10/09/advanced-ods-graphics-axis-tables-conta...

 

Here are two simple illustrations using formats.

 

data x;
   input age;
   n = _n_;
   datalines;
1
2
3
;

proc format;
   value agefmt 1 = 'Age'
                2 = "< 12"
                3 = "(*ESC*){Unicode '2265'x} 12";
run;


ods html body='b.html image_dpi=300';
ods graphics on / width=2in height=1.5in;
proc sgplot data=x;
   yaxistable age / position=left nolabel valuejustify=left;
   hbar n / barwidth=0.3;
   format age agefmt.;
   yaxis display=none;
   xaxis display=none;
   run;
ods html close;

data x2;
   input age $ 1-8;
   AxisVar = _n_;
   datalines;
Age
< 12
>= 12
;

data cntlin(keep=type fmtname start label);
   set x2;
   Type    = 'n';
   FmtName = "NewAgeFmt";
   Start   = axisvar;
   Label   = tranwrd(age, '>=', "(*ESC*){Unicode '2265'x}"); 
run;   

proc format cntlin=cntlin; quit;

ods html body='b.html image_dpi=300';
ods graphics on / width=2in height=1.5in;
proc sgplot data=x2;
   yaxistable axisvar / position=left nolabel valuejustify=left;
   hbar axisvar / barwidth=0.3;
   format axisvar newagefmt.;
   yaxis display=none;
   xaxis display=none;
   run;
ods html close;

 

Occasional Contributor
Posts: 12

Re: SGPlot YAXISTABLE greater than or equal symbol

Thanks.

 

Changing my diag variable to numeric and then applying the text as a format worked. Strange that the unicode symbols work with formats but not the underlying data values.

SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

Glad it worked!  At least for now, those are the only two mechanisms.  I will try to find a blog example of formats and post it with my original answer.

Highlighted
SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

I am going to write a blog where I provide an easy mechanism for generating a format that will handle some of the most common Unicode characters.  I appreciate the idea!

SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

This blog (insplired by your question) makes it easy to insert a number of special characters into axis tables.

 

https://blogs.sas.com/content/graphicallyspeaking/2017/10/09/advanced-ods-graphics-axis-tables-conta...

Occasional Contributor
Posts: 12

Re: SGPlot YAXISTABLE greater than or equal symbol

Thanks Warren,

 

This is very helpful. As an aside, I've added reference lines to complete the professional look to my forest plot. However, they are being restrained to the axis width. I assume the axisextent=data option is affecting them.

 

But in your code you have them spanning the whole graph axistables and scatter plot. Am I missing an option or keyword somewhere?

 

Could you advise?

 

Many thanks,

 

Daniel

 

proc sgplot data=table nowall noborder noautolegend dattrmap=attrmap;
	styleattrs axisextent=data;
	refline ref / lineattrs=(thickness=20 color=cxf0f0f7);

	scatter y=y_val x=sen / markerattrs=(symbol=squarefilled size=5 color=cx2A25D9) name='sens' legendlabel="Sensitivity";
	highlow y=y_val low=sen_l high=sen_u / lineattrs=(color=cx2A25D9 pattern=1) highcap=serif lowcap=serif transparency=0.3;

	scatter y=y_val x=spec / markerattrs=(symbol=diamondfilled size=5 color=cxB2182B) name='spec' legendlabel="Specificity";
	highlow y=y_val low=spec_l high=spec_u / lineattrs=(color=cxB2182B pattern=1) highcap=serif lowcap=serif transparency=0.3;

	yaxistable diag / valuejustify=left label labeljustify=left location=inside position=left labelattrs=(size=10pt weight=bold) textgroup=ind textgroupid=text;
	yaxistable area / label location=inside position=left labelattrs=(size=10pt weight=bold) textgroup=ind1 textgroupid=text;

	xaxis values=(0 to 100 by 10) label="% (95% CI)";
	yaxis reverse display=none;

	keylegend 'sens' 'spec' / position=top location=inside across=2 noborder;

run;

 

SAS Super FREQ
Posts: 205

Re: SGPlot YAXISTABLE greater than or equal symbol

Reference lines in axis tables are a bit tricky when you want them to extend the full width: 

https://blogs.sas.com/content/graphicallyspeaking/2017/06/01/8973/

 

It says:

PROC SGPLOT requires that you specify LOCATION=INSIDE for all of the Y-axis tables if you want reference lines to extend across the entire figure. It also requires you to display color bands in the Y axis. However, you can make them 100% transparent by specifying COLORBANDATTRS=(TRANSPARENCY=1).

 

ods rtf file="&file.Ref.rtf" style=pearl image_dpi=300;
* Draw the graph with reference lines;
proc sgplot data=plot4 noautolegend noborder dattrmap=attrmap;
   by bg;
   refline ref;
   yaxistable rowlab    / position=left textgroup=value textgroupid=aemap
                          pad=(right=.2in) location=inside;
   yaxistable acount ap / position=left labelattrs=(size=10px) location=inside
                          valueattrs=(color=red) labelattrs=(color=red) valuejustify=right;
   yaxistable bcount bp / position=left labelattrs=(size=10px) location=inside
                          valueattrs=(color=blue) labelattrs=(color=blue) valuejustify=right;
   scatter x=acount y=obsid / x2axis markerattrs=(symbol=circle   color=red  size=10);
   scatter x=bcount y=obsid / x2axis markerattrs=(symbol=triangle color=blue size=10);
   scatter x=acount y=obsid / markerattrs=(size=0);    /* bottom axis line */
   x2axis min=0 max=&x2max grid display=(noticks nolabel) valueattrs=(size=9px);
   xaxis display=(noticks nolabel novalues);
   yaxis display=none reverse colorbands=odd colorbandsattrs=(transparency=1) 
         thresholdmin=0 thresholdmax=0;
run;
ods rtf close;

Best,

Warren

Occasional Contributor
Posts: 12

Re: SGPlot YAXISTABLE greater than or equal symbol

Wonderful, thanks for the fast reply.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 242 views
  • 3 likes
  • 2 in conversation