Hi everyone.
I'm trying to make a format that includes the ≤ unicode sign.
I have searched the forums, but I cannot get the code to work.
proc format;
value highlowfmt
1 = '(*ESC*){unicode "2264"x} median '
2 = '> median';
run;
it runs without errors but doesn't output the unicode character
thanks in advance
You don't say why it doesn't work, but here is code that works for me. If it doesn't work for you, please tell us what you see or if the SAS log contains errors.
proc format;
value highlowfmt
1 = '(*ESC*){unicode "2264"x} median '
2 = '> median';
run;
data A;
format x highlowfmt.;
input x @@;
datalines;
1 2 2 1 1 1
;
proc print; run;
@Mrksk wrote:
Hi everyone.
I'm trying to make a format that includes the ≤ unicode sign.
I have searched the forums, but I cannot get the code to work.
proc format;
value highlowfmt
1 = '(*ESC*){unicode "2264"x} median '
2 = '> median';run;
it runs without errors but doesn't output the unicode character
Did you include the FORMAT statement in your data step or PROC?
It outputs "(*ESC*){unicode "2264"x} median" as the formatted value-
code:
proc format;
value highlowfmt
1 = '(*ESC*){unicode "2264"x} median '
2 = '> median';
run;
data A;
format x highlowfmt.;
input x @@;
datalines;
1 2 2 1 1 1
;
proc print; run;
log:
1 The SAS System 10:02 Tuesday, July 30, 2019
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program (7)';
4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5 %LET _CLIENTPROJECTPATH='H:\Dokumenter\NekrFasc\Nekrotiserende Fascitis Kohorte.egp';
6 %LET _CLIENTPROJECTPATHHOST='PC005760';
7 %LET _CLIENTPROJECTNAME='Nekrotiserende Fascitis Kohorte.egp';
8 %LET _SASPROGRAMFILE='';
9 %LET _SASPROGRAMFILEHOST='';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=PNG;
13 FILENAME EGSR TEMP;
14 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
15 STYLE=Journal1a
16 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/Journal1a.css")
17 NOGTITLE
18 NOGFOOTNOTE
19 GPATH=&sasworklocation
20 ENCODING=UTF8
21 options(rolap="on")
22 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
23
24 proc format;
25 value highlowfmt
26 1 = '(*ESC*){unicode "2264"x} median '
27 2 = '> median';
NOTE: Format HIGHLOWFMT is already on the library WORK.FORMATS.
NOTE: Format HIGHLOWFMT has been output.
28 run;
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
29
30 data A;
31 format x highlowfmt.;
32 input x @@;
33 datalines;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.A has 6 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
35 ;
36
37 proc print; run;
NOTE: There were 6 observations read from the data set WORK.A.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
2 The SAS System 10:02 Tuesday, July 30, 2019
38
39 %LET _CLIENTTASKLABEL=;
40 %LET _CLIENTPROCESSFLOWNAME=;
41 %LET _CLIENTPROJECTPATH=;
42 %LET _CLIENTPROJECTPATHHOST=;
43 %LET _CLIENTPROJECTNAME=;
44 %LET _SASPROGRAMFILE=;
45 %LET _SASPROGRAMFILEHOST=;
46
47 ;*';*";*/;quit;run;
48 ODS _ALL_ CLOSE;
49
50
51 QUIT; RUN;
52
output:
x
(*ESC*){unicode "2264"x} median
> median
> median
(*ESC*){unicode "2264"x} median
(*ESC*){unicode "2264"x} median
(*ESC*){unicode "2264"x} median
i think its an encoding issue.
on the same computer, the code works in base SAS 9.4, but it doesn't work in sas enterprise guide.
this is really strange to me
on the same computer, the code works in base SAS 9.4, but it doesn't work in sas enterprise guide.
Well, THAT's useful information!
What version of SAS are you running?
The special string '(*ESC*)' is the default "escape character" on modern SAS systems. It is possible that you are running an old system or that the default has been changed.
You can use the ODS EXCAPECHAR statement to define your own "escape character." In the following, a caret is used to indicate to ODS that unicode is being used in the format:
ODS ESCAPECHAR '^'; /* use caret for escape character */
proc format;
value highlowfmt
1 = '^{unicode "2264"x} median '
2 = '> median';
run;
data A;
format x highlowfmt.;
input x @@;
datalines;
1 2 2 1 1 1
;
proc print; run;
@Mrksk wrote:
Im on SAS enterprise guide 7.15 HF7 (7.100.5.6177) (64-bit)
Changing the escapechar like the above doesn't work
Not sure if the version of Enterprise Guide matters that much.
What version of SAS are you using to run the code?
That does NOT store the unicode character. It stores instructions that ODS will interpret to generate a unicode character. Note you have overcomplicated the syntax by making the unicode number look like a hex literal.
proc format;
value highlowfmt
1 = '(*ESC*){unicode 2264} median'
2 = '> median'
;
run;
So ODS outputs, like HTML should show the unicode character.
But text output will just show the text.
Obs value 1 (*ESC*){unicode 2264} median 2 > median
the sas version is 9.4
If it stores instructions that ODS will interpret to generate a unicode character, then it should display correctly on my ODS rtf output?
it doesn't
here the full code:
ods escapechar='^';
proc format;
value highlowfmt
1 = '^{unicode "2264"x} median '
2 = '> median';
run;
%macro SurvivalTemplateRestore;
%global TitleText0 TitleText1 TitleText2 yOptions xOptions tips
groups bandopts gridopts blockopts censored censorstr;
%let TitleText0 = METHOD " Survival Estimate";
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0 "s"; /* plural: Survival Estimates */
%let yOptions = label="Survival Probability"
shortlabel="Survival"
linearopts=(viewmin=0 viewmax=1
tickvaluelist=(0 .2 .4 .6 .8 1.0));
%let xOptions = shortlabel=XNAME
offsetmin=.05
linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS
tickvaluefitpolicy=XTICKVALFITPOL);
%let tips = rolename=(_tip1=ATRISK _tip2=EVENT) tip=(y x Time _tip1 _tip2);
%let groups = group=STRATUM index=STRATUMNUM;
%let bandopts = &groups modelname="Survival";
%let gridopts = autoalign=( bottomright)
border=false BackgroundColor=GraphWalls:Color Opaque=false;
%let blockopts = repeatedvalues=true valuehalign=start valuefitpolicy=truncate
labelposition=left labelattrs=GRAPHVALUETEXT
valueattrs=GRAPHDATATEXT(size=7pt) includemissingclass=false;
%let censored = markerattrs=(symbol=plus);
%let censorstr = "+ Censored";
%macro SurvivalTemplate;
proc template;
define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival;
dynamic NStrata xName plotAtRisk plotCL plotHW plotEP labelCL
%if %nrbquote(&censored) ne %then plotCensored;
labelHW labelEP maxTime xtickVals xtickValFitPol method StratumID
classAtRisk plotBand plotTest GroupName yMin Transparency SecondTitle
TestName pValue;
BeginGraph;
if (NSTRATA=1)
if (EXISTS(STRATUMID))
entrytitle &titletext1;
else
entrytitle &titletext0;
endif;
if (PLOTATRISK)
entrytitle "with Number of Subjects at Risk" / textattrs=
GRAPHVALUETEXT;
endif;
layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions);
%singlestratum
endlayout;
else
entrytitle &titletext2;
if (EXISTS(SECONDTITLE))
entrytitle SECONDTITLE / textattrs=GRAPHVALUETEXT;
endif;
layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions);
%multiplestrata
endlayout;
endif;
EndGraph;
end;
run;
%mend;
%macro entry_p;
if (PVALUE < .0001)
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4));
else
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4));
endif;
%mend;
%macro SingleStratum;
if (PLOTHW=1 AND PLOTEP=0)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE
name="HW" legendlabel=LABELHW;
endif;
if (PLOTHW=0 AND PLOTEP=1)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE
name="EP" legendlabel=LABELEP;
endif;
if (PLOTHW=1 AND PLOTEP=1)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHDATA1 datatransparency=.55
name="HW" legendlabel=LABELHW;
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHDATA2
datatransparency=.55 name="EP" legendlabel=LABELEP;
endif;
if (PLOTCL=1)
if (PLOTHW=1 OR PLOTEP=1)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
modelname="Survival" display=(outline)
outlineattrs=GRAPHPREDICTIONLIMITS name="CL" legendlabel=LABELCL;
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE name="CL"
legendlabel=LABELCL;
endif;
endif;
stepplot y=SURVIVAL x=TIME / name="Survival" &tips legendlabel="Survival";
if (PLOTCENSORED=1)
scatterplot y=CENSORED x=TIME / &censored
name="Censored" legendlabel="Censored";
endif;
if (PLOTCL=1 OR PLOTHW=1 OR PLOTEP=1)
discretelegend "Censored" "CL" "HW" "EP" / location=outside
halign=center;
else
if (PLOTCENSORED=1)
discretelegend "Censored" / location=inside
autoalign=(topright bottomleft);
endif;
endif;
if (PLOTATRISK=1)
innermargin / align=bottom;
blockplot x=TATRISK block=ATRISK / display=(values) &blockopts;
endinnermargin;
endif;
%mend;
%macro MultipleStrata;
if (PLOTHW)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
if (PLOTEP)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
if (PLOTCL)
if (PLOTBAND)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts
display=(outline);
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
endif;
stepplot y=SURVIVAL x=TIME / &groups name="Survival" &tips;
if (PLOTCENSORED)
scatterplot y=CENSORED x=TIME / &groups &censored;
endif;
if (PLOTATRISK)
innermargin / align=bottom;
blockplot x=TATRISK block=ATRISK / class=CLASSATRISK
display=(label values) &blockopts;
endinnermargin;
endif;
DiscreteLegend "Survival" / across=1 location=inside
autoalign=(TopRight BottomLeft Top Bottom);
if (PLOTCENSORED)
if (PLOTTEST)
layout gridded / rows=2 &gridopts;
entry &censorstr;
%entry_p
endlayout;
else
layout gridded / rows=1 &gridopts;
entry &censorstr;
endlayout;
endif;
else
if (PLOTTEST)
layout gridded / rows=1 &gridopts;
%entry_p
endlayout;
endif;
endif;
%mend;
%SurvivalTemplate
%mend;
ods noproctitle;
ods startpage=now;
ods rtf style=rtf file="H:\NSTI\lifetests.rtf" image_dpi=300 ;
ods graphics / reset noborder width=8.5cm ;
ods listing style=statistical ;
ods select SurvivalPlot (persist);
%SurvivalTemplateRestore;
%let TitleText0 = "MASP-1";
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0;
%SurvivalTemplate;
ods select SurvivalPlot (persist);
Proc lifetest data= nf.kohorte2 plots=(survival(test nocensor)) notable;
time Time_to_death_90Days*Mortality_90_days(0) ;
strata group_masp1;
format group_masp1 highlowfmt.;
run;
%SurvivalTemplateRestore;
and the output:
the format is not corrected on my ods output either. im on SAS 9.4
ods escapechar='^';
proc format;
value highlowfmt
1 = '^{unicode "2264"x} median '
2 = '> median';
run;
ods noproctitle;
ods startpage=now;
ods rtf style=rtf file="H:\NSTI\lifetests.rtf" image_dpi=300 ;
ods graphics / reset noborder width=8.5cm ;
ods listing style=statistical ;
ods select SurvivalPlot (persist);
%SurvivalTemplateRestore;
%let TitleText0 = "MASP-1";
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0;
%SurvivalTemplate;ods select SurvivalPlot (persist);
Proc lifetest data= nf.kohorte2 plots=(survival(test nocensor)) notable;
time Time_to_death_90Days*Mortality_90_days(0) ;
strata group_masp1;
format group_masp1 highlowfmt.;
run;
So the question is does ODS GRAPHICS support the UNICODE keyword?
From your example it looks like it does not. Did you search the documentation for ODS GRAPHICS to see if that restriction is documented?
Did you try including the actual UTF-8 code into the format instead?
proc format;
value highlowfmt
1 = 'E289A4'x ' median'
2 = '> median'
;
run;
Hopefully you can get it to work without going through the same extensive (confusing?) steps that were used is this article about PROC GLM graphics output. https://blogs.sas.com/content/graphicallyspeaking/2018/09/10/advanced-ods-graphics-unicode-tables-an...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.