Dear SAS-Community,
i want to have a -1 in superscript in the panel labels (= panelby variable) in SGPANEL (code below). I've tried it with a unicode from another forum post that i've used for the y-axis label (see code below) but it doesn't work. Does someone have a solution to my problem?
ods html5 style=analysis path="D:\Masterthesis\Statistik\2024\Grafiken" file="Unkraut-TM_25-4-24_Bhdlg.html"; ods graphics / width=4.5in; ods escapechar='^'; title height = 1.5 "Mittlere Unkraut-Trockenmasse der Behandlungen"; footnote "Behandlungen innerhalb einer Düngerstufe mit gleichem Buchstabe nicht signifikant voneinander verschieden"; data Unkraut_TM_Bhdlg_N0_MT1; set Unkraut_TM_Bhdlg_N0_MT1; Low = Median - Standardfehler; High = Median + Standardfehler; LabelPos = High + 0.4; run; data Unkraut_TM_Bhdlg_N0_MT1; set Unkraut_TM_Bhdlg_N0_MT1; if NStufe = 0 then NStufe_Label = "0 (kg ha^{unicode '207B'x}^{unicode '00B9'x})"; else if NStufe = 1 then NStufe_Label = "96 (kg ha^{unicode '207B'x}^{unicode '00B9'x})"; run; proc sgpanel data=Unkraut_TM_Bhdlg_N0_MT1; panelby NStufe_Label / noheaderborder headerattrs=(size=11pt weight=bold) novarname; vbarparm category=Behandlung response=Median / group=Behandlung groupdisplay=cluster; highlow x=Behandlung low=Low high=High / group=Behandlung lineattrs=(color=black thickness=1 pattern=solid) highcap=serif lowcap=serif; scatter x=Behandlung y=LabelPos / datalabel=Buchstabe; datalabelattrs=(size=10pt weight=bold color=black) datalabelpos=center markerattrs=(size=0); rowaxis label="Unkraut-TM (kg ha^{unicode '207B'x}^{unicode '00B9'x})" labelattrs=(size=11pt); colaxis display=none; run; ods html5 close;
Here is DanH_sas 's code for this question.
proc format;
value $super(default=80)
"F"="F (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x}"
"M"="M (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x}"
;
run;
proc sgpanel data=sashelp.class;
format sex $super.;
panelby sex / novarname headerattrs=(family="Arial Unicode MS" );
scatter x=weight y=height;
run;
You might try using PROC TEMPLATE and PROC SGRENDER -- see a bunch of examples here:
https://www.lexjansen.com/sesug/2022/SESUG2022_Paper_227_Final_PDF.pdf
...but it's likely more trouble than it's worth. I have tried to do something similar in SGPLOT -- trying to add superscripts to text specified in the TEXT statement, but I had no luck. That said, I did not try the above template / sgrender combo.
This question has been answered a couple of days before. Check this:
%let label1=weight (*ESC*){sup 'mw -1'} ;
%let label2=height (*ESC*){sub 'mw -1'} ;
/*用于加X轴Y轴标签的上下标*/
data _anno;
length label $ 200;
drawspace="layoutpercent"; function="text"; textweight="normal"; textsize=12;textcolor="black"; width=200;
x1=55; y1=2.5;label="&label1."; output;
x1=2.5; y1=55;rotate=90;label="&label2."; output;
run;
/*****画散点图*****/
proc sgpanel data=sashelp.class sganno=_anno;
panelby sex;
scatter x=weight y=height;
rowaxis label=' ';
colaxis label=' ';
run;
To do this for classification values in a variable (such as your panel variable), you will need to use a user-defined format. See the simple example below. Note that, in a user-defined format, you MUST use the default escape sequence (*ESC*) instead of a defined escapechar.
proc format;
value $super
"F"="R(*ESC*){unicode '00b2'x}"
"M"="D(*ESC*){unicode '00b2'x}"
;
run;
proc sgpanel data=sashelp.class;
format sex $super.;
panelby sex / novarname;
scatter x=weight y=height;
run;
Thank you really much for your help 🙂.
Here is DanH_sas 's code for this question.
proc format;
value $super(default=80)
"F"="F (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x}"
"M"="M (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x}"
;
run;
proc sgpanel data=sashelp.class;
format sex $super.;
panelby sex / novarname headerattrs=(family="Arial Unicode MS" );
scatter x=weight y=height;
run;
Thank you really much for your help 🙂.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.