<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965102#M375787</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I am trying to concatenate multiple RTF reports into a single RTF file by importing into SAS data and Exporting to Combine RTF file. When I am doing that everything is transferred exactly except the leading spaces in column labels for indentation purpose so, could anyone help me with this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am getting the same leading spaces from import of RTF in the final dataset that is ready to export but it is not showing in the concatenated RTF File. The below is the SAS code to Export the data into RTF file&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data _null_;
  set result_s1 end=eof ;
  file "../../documentation/combined.rtf" ;
  if not delete then do;
    if outrtf eq "" then put inrtf;
    else do;
      if eof then put inrtf;
      else put outrtf;
    end;
   end;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Dataset with preserved leading spaces" style="width: 814px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106509iAC526F45765EA27D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-24 204520.png" alt="SAS Dataset with preserved leading spaces" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;SAS Dataset with preserved leading spaces&lt;/span&gt;&lt;/span&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
    <pubDate>Fri, 25 Apr 2025 09:30:53 GMT</pubDate>
    <dc:creator>Khadar_Shaik</dc:creator>
    <dc:date>2025-04-25T09:30:53Z</dc:date>
    <item>
      <title>Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965102#M375787</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to concatenate multiple RTF reports into a single RTF file by importing into SAS data and Exporting to Combine RTF file. When I am doing that everything is transferred exactly except the leading spaces in column labels for indentation purpose so, could anyone help me with this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am getting the same leading spaces from import of RTF in the final dataset that is ready to export but it is not showing in the concatenated RTF File. The below is the SAS code to Export the data into RTF file&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data _null_;
  set result_s1 end=eof ;
  file "../../documentation/combined.rtf" ;
  if not delete then do;
    if outrtf eq "" then put inrtf;
    else do;
      if eof then put inrtf;
      else put outrtf;
    end;
   end;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Dataset with preserved leading spaces" style="width: 814px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106509iAC526F45765EA27D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-24 204520.png" alt="SAS Dataset with preserved leading spaces" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;SAS Dataset with preserved leading spaces&lt;/span&gt;&lt;/span&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Apr 2025 09:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965102#M375787</guid>
      <dc:creator>Khadar_Shaik</dc:creator>
      <dc:date>2025-04-25T09:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965104#M375788</link>
      <description>&lt;P&gt;Are the leading spaces you're trying to preserve the ONLY spaces in the document?&amp;nbsp; If so, then a hack-y kind of way to do this is to simply replace all the spaces with some character and then, in your output RTF file, find/replace those characters back to spaces.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
(in your data _null_ step... -- use some character that doesn't otherwise appear in your data.)

inrtf=tranwrd(inrtf, ' ', '#');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there's no single character that's certain not to appear in your data, then just replace spaces with a string, e.g. "#SPACE#"&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 10:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965104#M375788</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-25T10:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965105#M375789</link>
      <description>&lt;P&gt;This will make more manual work if we have more files or more pages in the same report.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 10:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965105#M375789</guid>
      <dc:creator>Khadar_Shaik</dc:creator>
      <dc:date>2025-04-25T10:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965106#M375790</link>
      <description>&lt;P&gt;The normal $ format does not preserve leading spaces.&amp;nbsp; Use either $CHAR or $VARYING.&amp;nbsp; For this application $VARYING is better since it will not add extra trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set result_s1 end=eof ;
  file "../../documentation/combined.rtf" ;
  if not delete then do;
    len_in=lengthn(inrtf);
    len_out=lengthn(outrtf);
    if outrtf eq "" then put inrtf $varying3000. len_in;
    else do;
      if eof then put inrtf $varying3000. len_in;
      else put outrtf $varying3000. len_out;
    end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could probably simplify the logic by using the COALESCEC() function.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set result_s1 end=eof ;
  file "../../documentation/combined.rtf" ;
  if not delete;
  outrtf=coalescec(outrtf,inrtf);
  len_out=lengthn(outrtf);
  put outrtf $varying3000. len_out;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I don't understand why you wanted the special case for the last line.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 14:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965106#M375790</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-25T14:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Spaces are removed when RTF scripted SAS dataset to Export into RTF</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965113#M375792</link>
      <description>&lt;P&gt;Note that you will have a similar issue when using the $ INFORMAT to read in the original file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this text file:&lt;/P&gt;
&lt;PRE&gt;This in example
  file with some
     lines with 
       leading
spaces.  And some lines
without.&lt;/PRE&gt;
&lt;P&gt;You can read it in using the automatic _INFILE_ variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile rtf ;
  input;
  line=_infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use the $CHAR informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile rtf truncover;
  input line $char300.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can write it out using the $VARYING format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  file out;
  len=lengthn(line);
  put line $varying300. len ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the LIST statement to check the contents:&lt;/P&gt;
&lt;PRE&gt;56   data _null_;
57     infile out;
58     input;
59     list;
60   run;

NOTE: The infile OUT is:

      Filename=C:\Users\...\#LN00012,
      RECFM=V,LRECL=32767,File Size (bytes)=103,
      Last Modified=25Apr2025:07:59:58,
      Create Time=25Apr2025:07:59:58

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+---
1         This in example 15
2           file with some 16
3              lines with 15
4                leading 14
5         spaces.  And some lines 23
6         without. 8
NOTE: 6 records were read from the infile OUT.
      The minimum record length was 8.
      The maximum record length was 23.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Apr 2025 14:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Spaces-are-removed-when-RTF-scripted-SAS-dataset-to/m-p/965113#M375792</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-25T14:08:13Z</dc:date>
    </item>
  </channel>
</rss>

