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

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

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Rhodochrosite | Level 12

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

8 REPLIES 8
WarrenKuhfeld
Rhodochrosite | Level 12

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;

 

DGrint
Obsidian | Level 7

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.

WarrenKuhfeld
Rhodochrosite | Level 12

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.

WarrenKuhfeld
Rhodochrosite | Level 12

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!

WarrenKuhfeld
Rhodochrosite | Level 12

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...

DGrint
Obsidian | Level 7

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;

 

WarrenKuhfeld
Rhodochrosite | Level 12

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

DGrint
Obsidian | Level 7

Wonderful, thanks for the fast reply.

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
  • 8 replies
  • 3332 views
  • 3 likes
  • 2 in conversation