SAS - how to realize output font freedom

Posted by jkohns on Sat, 18 Dec 2021 15:07:58 +0100

Xiaobian today to share how SAS output RTF realizes font freedom. This paper will mainly introduce the implementation method of SAS output RTF to realize "Chinese Song typeface, English Times New Roman". Before that, let's share the solution to the invalidation of the "Tahoma" setting.

Set "Tahoma" invalid

In Style, the font is set to "Arial", but the final output font is "isocline". In fact, this problem is also well solved. We can replace "Arial" with "simsun".

Set Style in Proc Template

Chinese "Song Ti", English "new Rome"

As for how to realize font freedom, I will take how to realize "Chinese song style, English new Rome" as an example. There are many such questions on the Internet, but they are often fruitless or impossible to achieve. The implementation idea of small editing is mainly divided into three steps ([custom font] - [install and import font] - [set font and output]). In fact, with the idea, the implementation is really simple.

Custom font

As a programmer, logical thinking is very important. Since the existing fonts can not meet our needs, in fact, we can define or create the fonts we need. You can find some free font editors on the Internet that can be used to create fonts. Xiaobian replaced letters / numbers / symbols with a new roman font based on the existing Song typeface, so a custom font came into being. Xiaobian named it "Times New Roman".

style editor

Install / import fonts

Install the custom font on the computer (probably Xiaobian. The essence of the custom font here is the combination of "song style" and "Times New Roman", which can be displayed normally even if the custom font is not installed on other computers), and then import it into SAS.

install font

Double click to open the font and click Install

Import SAS

/*Write the font to the SAS registry, and fill in the path where the font is located in fontpath*/
proc fontreg mode=all ;
fontpath 'E:\Daily programming\SAS Macro program launch\Font settings\typeface';
run;

Set output

Finally, you can set the Proc template and ODS output.

proc template;
  define style tp_rtf;
  parent = styles.rtf;
  replace  fonts /
      "TitleFont2" = ("Song typeface(Times New Roman)",9pt)
      "TitleFont" = ("Song typeface(Times New Roman)",9pt)
      "StrongFont" = ("Song typeface(Times New Roman)",9pt,Bold)
      "EmphasisFont" = ("Song typeface(Times New Roman)",9pt,Italic)
      "FixedEmphasisFont" = ("Song typeface(Times New Roman)",9pt,Italic)
      "FixedStrongFont" = ("Song typeface(Times New Roman)",9pt)
      "FixedHeadingFont" = ("Song typeface(Times New Roman)",10pt)
      "BatchFixedFont" = ("Song typeface(Times New Roman)",10pt)
      "FixedFont" = ("Song typeface(Times New Roman)",9pt)
      "headingEmphasisFont" = ("Song typeface(Times New Roman)",10pt,Bold Italic)
      "headingFont" = ("Song typeface(Times New Roman)",10pt,Bold)
      "docFont" = ("Song typeface(Times New Roman)",9pt);
  replace Header from HeadersandFooters / font = ("Song typeface(Times New Roman)", 9pt, medium)
      background = _undef_
      protectspecialchars = off;
  replace table from output / font = ("Song typeface(Times New Roman)", 9pt, medium)
      background = _undef_
      frame = void
      rules = none
      cellspacing = 0.5pt
      cellpadding = 1pt
      outputwidth = 100%;;
  replace cell from output /
      font = ("Song typeface(Times New Roman)", 9pt, medium) ;
      *Define header;
      style header /
      backgroundcolor=white
      color=black
      fontweight=bold;
  *Define the layout of the file;
  style body from document /
      bottommargin = 15mm
      topmargin = 15mm
      rightmargin = 15mm
      leftmargin = 15 mm;
  end;
run;

Result display

Double result display

summary

I believe that after reading the above, it is a very simple thing to realize font freedom.