Hi All,
There are both Chinese and English characters in my report. I want to use the Time New Roman font for the English characters and the SimSun font for the Chinese ones.
I tried a font-face list "Times New Roman, Simsun" in my style definition. Given the Time New Roman font has no glyph for Chinese characters, I think the SimSun font will be applied for Chinese. This method is often used in CSS.
But the result is not what I expected. Word processor says the Chinese characters in my report have a monospace font (等线字体) rather than SimSun.
By the way, if I changed Time New Roman to Courier. It works. Courier is a kind of monospace font. Does the font type matter?
Anyway, I want to know whether my idea is feasible in SAS. The following is my program sample. I program in an unicode session and both kinds of fonts have been registered in SAS.
Many thanks for your help in advanced!
proc template;
define style MyStyle;
parent = styles.Printer;
class fonts /
'TitleFont' = ("'Times New Roman',Simsun",10.5pt,Bold)
'TitleFont2' = ("'Times New Roman',Simsun",10.5pt,Bold)
'StrongFont' = ("'Times New Roman',Simsun",10.5pt,Bold)
'EmphasisFont' = ("'Times New Roman',Simsun",10.5pt,Italic)
'FixedEmphasisFont' = ("'Times New Roman',Simsun",10.5pt,Italic)
'FixedStrongFont' = ("'Times New Roman',Simsun",10.5pt,Bold)
'FixedHeadingFont' = ("'Times New Roman',Simsun",10.5pt,Bold)
'BatchFixedFont' = ("'Times New Roman',Simsun",10.5pt)
'FixedFont' = ("'Times New Roman',Simsun",10.5pt)
'headingEmphasisFont' = ("'Times New Roman',Simsun",10.5pt,Bold Italic )
'headingFont' = ("'Times New Roman',Simsun",10.5pt,Bold)
'docFont' = ("'Times New Roman',Simsun",10.5pt)
;
end;
run;
data test;
a = "你好, 世界";
b = "Hello, world!";
run;
options nonumber nodate;
ods rtf file="test.rtf" style=MyStyle;
proc report data=test;
run;
ods rtf close;
This is how I set 2 fonts for one table cell, it's mannually, you can surely convert it to program work.
您好,您尝试了行内格式化吗?您可以通过ods escapechar语句搭配{}号修改一段文字中部分(而不是全部)文字的字体。
Hello, have you ever tried inline formatting? You can use ods escapechar statement along with {} symbols to modify part of (instead of the entirety of) the fonts of a line of words.
示例代码如下:
Example code are as follows:
proc report data=xxx style=a /*你在PROC TEMPLATE设置好的模板名(name of the template you have set up in PROC TEMPLATE)*/
style(header)=[fontfamily="Times New Roman"]
style(column)=[fontfamily="Times New Roman"];
col a b;
ods escapechar '^';
define a/display "^{style[fontfamily="Simsun"] 中文}bianliangming";
define b/display "English variable name";
run;
在刚才这段代码中,我默认把所有标题和表格内容的字体设置成Times New Roman,再用ods escapechar语句搭配在define语句的{}号中将行标题的中文部分改为Simsun。
In the preceding code, I set the fonts of the entirety of the headers and table contents as Times New Roman and changed the Chinese part of the column header into Simsun by the duo of ods escapechar statement and the {} symbols in the define statement.
很抱歉,如果是这样的话,那我也确实不知道怎么在SAS中解决这个问题了。不过我觉得可以绕过SAS解决它。您可以通过先将PROC REPORT生成的报告导出,然后在Microsoft Office或WPS等办公软件内全选您的报告后修改字体。例如,在Microsoft Word中,您全选报告后点击鼠标右键,选择“字体”,在弹出的窗口中分别修改“中文字体”和“英文字体”。如果您的目标是生成一份PDF,可以先把报告导出成一份RTF文件,在RTF文件内修改字体后再通过另存为等方式转换为PDF。这样就能达成批量转换中英文字体的目标。
Sorry, if that is the case, then I really do not know how to tackle this problem in SAS. But I think we can bypass SAS in the course of addressing this problem. You can first output your report generated by PROC REPORT, and then change fonts in softwares like Microsoft Office and WPS. For instance, in Microsoft Word, you select the entire report, right-click the mouse and choose "Fonts". In the popped up window, you can change "Chinese Font" and "English font" respectively. If your objective is to generate a PDF, you can first output your report into a RTF document, change fonts in the RTF document and then transform it into a PDF by means like "Saved as...". In this way, you achieve the goal of transforming Chinese and English fonts in batches.
Hi Season,
Thank you! I think you are right. I begin to realize this is not feasible in SAS.
Actually when I checked the RTF source code, I found the Simsun font was never specified in the RTF font table whether I used the font list "Times New Roman, SimSun" or "Courier, Sumsun".
Anyway, your patience and help is greatly appreciated!
也许您可以试试把RTF先另存为一份.doc或.docx文档,然后在另存为的文档上更改字体。
Maybe you can try saving your RTF as a .doc or .docx document and change fonts in that document.
本论坛上有几位网友是ODS的高手,也许您可以咨询他们:@Rick_SAS、 @Ksharp、 @PaigeMiller。
There are several users of this Community who are very skilled at ODS. Maybe you can ask them: @Rick_SAS, @Ksharp, @PaigeMiller.
另外,您也可以到微信上的SAS论坛去咨询。您在微信里添加“数科赛仕”微信公众号后可以在公众号中进入中文版SAS论坛。那里的中文用户更多,相信也有人遇到了和您类似的问题。
In addition, you can also raise your questions in the SAS Forum on Wechat. You can enter the Chinese edition of SAS forum via the account named "数科赛仕" after adding this account as your friend. There are more Chinese users there and I believe that someone has encountered similar problems.
最后,我推荐几位SAS畅销书的作者。我经常阅读他们写的书,包括他们写的关于ODS的内容,受益匪浅。您也可以问问他们。不过我不确定他们在这个论坛上有没有账号,您还得自行寻找他们的联系方式。他们是冯国双、胡良平、谷鸿秋和Art Carpenter。
Finally, I would like to recommend several authors of SAS bestsellers, whose books, including those concerning ODS, are frequently consulted by me. I benefit I lot from their contributions. You can also seek for their help. But I am not sure if they have accounts on this Community. You have to look for their contact information themselves. They are Guoshuang Feng (冯国双), Liangping Hu (胡良平), Hongqiu Gu (谷鸿秋) and Art Carpenter.
祝您好运!也烦请您在知晓如何用ODS解决您这个问题后在这个论坛上回帖,和大家说一下解决方案。我本人对如何处理这个问题也很感兴趣。
Wish you good luck! Please post the ODS solutions to this problem here on this Community so that others can get informed. I personally am interested in how to tackle this problem.
It would be worth finding out if the SAS installation being used has multi-language support installed. When you install SAS you have the option of installing multiple languages or just installing English. If support for Chinese languages is not installed then it is unlikely you can use Chinese characters in PROC REPORT.
You can read about SAS's NLS support here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/titlepage.htm
Thank you for your reply! Actually, it was @chiwei instead of me who was stuck on the problem mentioned in this topic. I am not sure if @chiwei has multi-language support installed but I think the curx of the problem raised by @chiwei was that he or she was trying to build a bilingual report and automatically designate the fonts of English and Chinese characters respectively. Moreover, the exact wordings are not pre-defined, a condition required for inline formatting.
Hi both,
I can make sure that
I guess ODS RTF just does not work like CSS in Web, though the ODS RTF statement supports a CSSSTYLE option. It seems it just uses the first kind of font it can find.
In my system, use the font list “Times New Roman, SimSun”,the font table in RTF is:
{\fonttbl {\f1\froman\fprq2\fcharset134\cpg936 Times New Roman;} {\f2\froman\fprq2\fcharset134\cpg936 Times;} }
For the font list “Courier, Sumsun”, it is:
{\fonttbl {\f1\fmodern\fprq1\fcharset134\cpg936 Courier;} {\f2\froman\fprq2\fcharset134\cpg936 Times;} }
When I open an RTF file specifying a font doesn't support Chinese characters, the system just uses a default font to display Chinese.
This is how I set 2 fonts for one table cell, it's mannually, you can surely convert it to program work.
哇噢!这真的很酷!您可以讲解一下您的操作流程(尤其是您在记事本中修改的代码的含义)吗?另外,@chiwei 提出的要求是将所有中文字体改为Simsun。经过您的修改,RTF文件中的中文字体变为宋体,而不是Simsun。
Woh! That is really cool! Could you please elaborate the opertaional procedure (especially the meaning of codes you altered in Notepad)? By the way, @chiwei proposed the request of setting the font of all Chinese characters to Simsun. After your modification, the font of Chinese characters in the RTF file was changed into 宋体 instead of Simsun.
Since we all use Chinese, please allow me to use Chinese to make it clear, my English is not so good.
我的灵感来自于 @chiwei 在楼上发布的 font table 的展示:
{\fonttbl
{\f1\froman\fprq2\fcharset134\cpg936 Times New Roman;}
{\f2\froman\fprq2\fcharset134\cpg936 Times;}
}
并且他提到:It seems it just uses the first kind of font it can find.
我注意到 font table 中定义了两种字体,于是找到 RTF Specification,挨个查询了控制字“\f1\froman\fprq2\fcharset134\cpg936
”的含义,发现 \fn 代表着字体引用名(这有些像 SAS 中的文件引用名)。
既然定义了两种字体,为何仅让西文显示为 Times New Roman 字体,而中文显示为默认的字体(在我的机器上是等线)呢?我尝试用 SAS 生成了一份默认样式的 RTF 文件,经过一番观察,很快发现在每个单元格的值前面,也有一堆控制字,用来控制单元格内容的字体、颜色、字号等样式,其中就有 \f1,但所有的单元格都没有引用 \f2。
我记起来,在 MS Word 软件中,为一个单元格设置多个字体,是这样做的:选中单元格全部内容,将字体先设置为宋体,然后再设置为 Times New Roman。于是,我试着将 font table 中的两个字体分别定义为宋体和 Times New Roman,然后在单元格的样式控制字 \f1 的后面加上 \f2,使得每个单元格都先后应用这两个字体。
就这样成功了。
一些团队可能会使用宏来进行报表的输出,将上述手动操作转换成代码命令,然后放在宏的内部,应该会很干净地完成任务。
谢谢您的详细阐述!我也涨了知识了!我觉得您可以把这些对@chiwei的问题的答复整理成一篇论文,发表在SAS使用者小组(SAS User Groups, SUGs)上。我认为这个问题很重要,但目前为止我还不知道有其他人给出了答案。
I think Simsun is 宋体, I have learned it long ago.
Just checked it on my computer, in "C:\Windows\Fonts", a font displayed as "宋体 常规". When I review its attributes, I see the path is: C:\Windows\Fonts\simsun.ttc
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.