I want to create some graphs for different distributions using mu and sigma and other possible characters.
I'm starting with the normal distribution. The first format works in sgplot. The second format with subscripts doesn't work. What am I doing wrong. I am on SAS 9.4 M5 in the Windows 10 system.
Thank you
dm 'log;clear;out;clear;';
options nonumber nodate orientation=landscape ps=49 nodate;
ods html;
ods rtf file="C:\data\test.rtf";
data data1;
sigma=9;
pop=1;
do X=sigma/2-3*sqrt(sigma) to sigma/2+3*sqrt(sigma) by .1;
f=(1/sqrt(2*3.14159*sigma))*exp((-1/2/sigma)*(X-sigma/2)**2);
output; end;
pop=2;
do X=-sigma/2-3*sqrt(sigma) to -sigma/2+3*sqrt(sigma) by .1;
f=(1/sqrt(2*3.14159*sigma))*exp((-1/2/sigma)*(X+sigma/2)**2);
output; end;
cards;
run;
proc format;
VALUE stds
-13.5 = "(*ESC*){Unicode mu} - 2(*ESC*){Unicode sigma}"
-9.0 = "(*ESC*){Unicode mu} - (*ESC*){Unicode sigma}"
-4.5 = "(*ESC*){Unicode mu}"
0.0 = "(*ESC*){Unicode mu} + (*ESC*){Unicode sigma}"
4.5 = "(*ESC*){Unicode mu} + 2(*ESC*){Unicode sigma}"
;
run;
proc format;
VALUE stdsb
-13.5 = "(*ESC*){Unicode mu}(*ESC*){sub 0} - 2(*ESC*){Unicode sigma}"
-9.0 = "(*ESC*){Unicode mu}(*ESC*){sub 0} - (*ESC*){Unicode sigma}"
-4.5 = "(*ESC*){Unicode mu}(*ESC*){sub 0}"
0.0 = "(*ESC*){Unicode mu}(*ESC*){sub 0} + (*ESC*){Unicode sigma}"
4.5 = "(*ESC*){Unicode mu}(*ESC*){sub 0} + 2(*ESC*){Unicode sigma}"
;
run;
data one;
input x;
cards;
-13.5
-9.0
-4.5
0.0
4.5
;
run;
Title "Does the format work in a simple proc print";
title2 "Try the simpler format without subscripts first";
proc print data=one; var x; format x stds.; run;
title2 "Try the format with subscripts. Which works with proc print";
proc print data=one; var x; format x stdsb.; run;
goptions device=win hsize=7 vsize=7;
Title "Does the format work with sgplot";
title2 "Try the simpler format without subscripts first. Note this format works";
proc sgplot data=data1;
series y=f x=X/group=pop;
xaxis values=(-13.5 to 4.5 by 4.5) valuesformat=stds.;
yaxis values=(0 to .2 by .02);
where pop=2;
footnote1 c=black 'Normal Distribution of X for one Population.';
run;
goptions device=win hsize=7 vsize=7;
Title "Does the format work with sgplot";
title2 "Try the format with subscripts. Note this format doesn't work";
proc sgplot data=data1;
series y=f x=X/group=pop;
xaxis values=(-13.5 to 4.5 by 4.5) valuesformat=stdsb.;
yaxis values=(0 to .2 by .02);
where pop=2;
footnote1 c=black 'Normal Distribution of X for one Population.';
run;
ods rtf close;
Plot from first format:
Plot from second format:
Thank you.
i don't have the support I did get a box.
I think you have a typo in your proc sgplot. When I removed the , in valueattrs it ran perfectly.
I am only using the Unicode due to fact that this the first time that I have since code that gives SAS the ability to print these types of characters. Is there a better option?
Thank you
John
SUP and SUB are not currently supported for axis tick marks. You have to use the Unicode equivalents. In your case:
proc format;
VALUE stdsb
-13.5 = "(*ESC*){Unicode mu}(*ESC*){Unicode '2080'x} - 2(*ESC*){Unicode sigma}"
-9.0 = "(*ESC*){Unicode mu}(*ESC*){Unicode '2080'x} - (*ESC*){Unicode sigma}"
-4.5 = "(*ESC*){Unicode mu}(*ESC*){Unicode '2080'x}"
0.0 = "(*ESC*){Unicode mu}(*ESC*){Unicode '2080'x} + (*ESC*){Unicode sigma}"
4.5 = "(*ESC*){Unicode mu}(*ESC*){Unicode '2080'x} + 2(*ESC*){Unicode sigma}"
;
run;
Given that the "sub 0" is in the 2000 Unicode range, it is possible that the font you're using might not have that glyph (it will show up as a box). If that happens, we ship fonts that do support those glyphs. If the font you're using in your plot is a san-serif, try using "Arial Unicode MS", like this:
proc sgplot data=data1;
series y=f x=X/group=pop;
xaxis values=(-13.5 to 4.5 by 4.5) valuesformat=stdsb.
valueattrs=(family="Arial Unicode MS" size=9pt);
yaxis values=(0 to .2 by .02);
where pop=2;
footnote1 c=black 'Normal Distribution of X for one Population.';
run;
For serif fonts, try "Times New Roman Uni".
Hope this helps!
Dan
Thank you.
i don't have the support I did get a box.
I think you have a typo in your proc sgplot. When I removed the , in valueattrs it ran perfectly.
I am only using the Unicode due to fact that this the first time that I have since code that gives SAS the ability to print these types of characters. Is there a better option?
Thank you
John
Fixed it 🙂
Thanks!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.