create RTF file from ASCII file

Hi SAS Users

I have recently faced the problem: I had to create RTF file
from ASCII file with the following specifications:

1.   Landscape orientation
2.   Left margin=1.1in
3.   Right margin=0.5in
4.   Top margin=1in
5.   Bottom margin=0.5in
6.   Font=SAS Monospace
7.   Font size=8
8.   Space between lines=exactly 7.6pt
9.   Once RTF file is opened in MSWord it should look like
MSWord document, but not MSWord table (with columns and

It seems like ODS RTF cannot accomplish exactly what I
needed. However it is possible if RTF file is build

Here is the code:

filename ascii "...my current ASCII file name...";
filename rtf "...my future RTF file...";

data _null_;
  infile ascii length=ln end=final;
  file rtf;

  length line $200;
  input line $varying200. ln;

  ** use backslash (\) and braces ({}) as text, not as RTF control
  if index(line,"\") then line=tranwrd(trim(line),"\","\\");
  if index(line,"{") then line=tranwrd(trim(line),"{","\{");
  if index(line,"}") then line=tranwrd(trim(line),"}","\}");

  ** page breaks;
  if index(line,"0C"x) then line=tranwrd(trim(line),"0C"x,"\page");

  ** start of rtf;
  if _n_=1 then do;

    put "{\rtf";

    ** font table;
    ** Note, blank space can cause problems;
    put "\deff3";  ** default font;
    put "{\fonttbl";
    put "{\f0 Times New Roman}";
    put "{\f1 Arial}";
    put "{\f2 Symbol}";
    put "{\f3 SAS Monospace}";
    put "{\f4 Courier}";
    put "}";

    ** Margins (1440 twips = 1 in);
    put "\margl1584\margr720\margt1440\margb720";

    ** Print layout view;
    ** Another options:
    ** \viewkind0 - None;
    ** \viewkind2 - Outline view;
    ** \viewkind3 - Master Document view;
    ** \viewkind4 - Normal view;
    ** \viewkind5 - Online Layout view;
    put "\viewkind1";

    ** landscape (1440 twips = 1 in);
    put "\lndscpsxn\paperw15840\paperh12240";

    ** line spacing \sl[N] (20 = 1 pt);
    ** negative number (-152 = 7.6pt) is used to ensure specified;
    ** line spacing even if it is shorter than the tallest character;
    ** \slmult0 - Exactly Line spacing;
    ** Another option:;
    ** \slmult1 - Single Line spacing;
    put "\sl-152\slmult0";

    ** font size \fs[N] (2 = 1 pt);
    ** Font 3 (SAS Monospace) Size 8;
    put "\f3\fs16";

  put line $varying200. lg @;

  if final then put / "}";
  else put "\line";  ** line break;

If you are interested in this approach the complete RTF
documentation can be found at
My thanks to Rober Worman for his great help with this issue.

Philip Primak

pprimak (29)
9/6/2005 9:01:14 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

0 Replies

Similar Articles

[PageSpeed] 15