<?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 Re: Retain leading/trailing spaces while exporting SAS dataset to flat files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984781#M379736</link>
    <description>&lt;P&gt;You will want to repost your examples, input and output both, into a TEXT box on the forum. Open a text box by clicking on the &amp;lt;/&amp;gt; icon that appears above the main message window and paste the text. The software of the forum mean that the main message windows&amp;nbsp;&lt;STRONG&gt;will&lt;/STRONG&gt; reformat pasted text and replace white space characters which means that we will not see what you want if the examples are pasted into the main message window.&lt;/P&gt;</description>
    <pubDate>Sat, 14 Mar 2026 12:49:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2026-03-14T12:49:40Z</dc:date>
    <item>
      <title>Retain leading/trailing spaces while exporting SAS dataset to flat files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984771#M379734</link>
      <description>&lt;P&gt;I want to retain leading/trailing spaces while exporting data into a flat file, using below code its getting trimmed currently.&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set test_data end=eof;&lt;BR /&gt;file "&amp;lt;location&amp;gt;/test_data.dat" dlm='01'x DSD encoding="utf-8" bom=no;&lt;BR /&gt;retain out_rec_count 0;&lt;BR /&gt;out_rec_count + 1;&lt;BR /&gt;put mmn rec_seq;&lt;BR /&gt;if eof then do;&lt;BR /&gt;call symputx('out_record_count', out_rec_count);&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;input dataset ::&lt;BR /&gt;mmn|rec_seq&lt;BR /&gt;&amp;nbsp;|1&lt;BR /&gt;MarY |2&lt;BR /&gt;&amp;nbsp;John |3&lt;BR /&gt;QUIIN |4&lt;BR /&gt;&amp;nbsp;1234 john |5&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;current output file :&lt;/STRONG&gt;&lt;BR /&gt;^A1&lt;BR /&gt;MarY^A2&lt;BR /&gt;John^A3&lt;/P&gt;&lt;P&gt;QUIIN^A4&lt;BR /&gt;1234 john^A5&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;expected output file :&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;^A1&lt;BR /&gt;MarY ^A2&lt;BR /&gt;&amp;nbsp;John ^A3&lt;BR /&gt;QUIIN ^A4&lt;BR /&gt;&amp;nbsp;1234 john ^A5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using $char50. in put statement, but it adds addition spaces to keep 50 length. Please suggest solution.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2026 01:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984771#M379734</guid>
      <dc:creator>PRAVIN_JAIN</dc:creator>
      <dc:date>2026-03-14T01:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retain leading/trailing spaces while exporting SAS dataset to flat files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984781#M379736</link>
      <description>&lt;P&gt;You will want to repost your examples, input and output both, into a TEXT box on the forum. Open a text box by clicking on the &amp;lt;/&amp;gt; icon that appears above the main message window and paste the text. The software of the forum mean that the main message windows&amp;nbsp;&lt;STRONG&gt;will&lt;/STRONG&gt; reformat pasted text and replace white space characters which means that we will not see what you want if the examples are pasted into the main message window.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2026 12:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984781#M379736</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-03-14T12:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Retain leading/trailing spaces while exporting SAS dataset to flat files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984784#M379737</link>
      <description>&lt;P&gt;Please show the SAS code you used to write the file that did not work.&amp;nbsp; Note that using the DSD option implies that the leading/trailing spaces will be removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why exactly would you want to include leading or trailing spaces into a delimited text file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can you know how many trailing spaces to include?&amp;nbsp; SAS character variables are fixed length.&amp;nbsp; So&amp;nbsp;they are always padded with enough spaces to fill them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know the length you want to print use the $VARYING format.&amp;nbsp; That requires a separate variable with the length to be printed.&lt;/P&gt;
&lt;P&gt;Try this data step to see how it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length string $10 ;
  string="   abc";
  do i=0 to 10;
    put '|' string $varying100. i '|';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2026 16:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984784#M379737</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-14T16:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Retain leading/trailing spaces while exporting SAS dataset to flat files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984785#M379738</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/176322"&gt;@PRAVIN_JAIN&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The number of trailing spaces in variable MMN is determined by the length of that variable (and, of course, its values). So, if you want to preserve exactly those spaces and also the leading spaces while creating a delimited text file, use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0jks6tlw4a1v1n1ssob6gtpxfth.htm" target="_blank" rel="noopener"&gt;formatted output&lt;/A&gt; (at least for variable MMN) with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n1oily9h2mwp5cn1dtb5qu8tcj7u.htm" target="_blank" rel="noopener"&gt;$CHAR. format&lt;/A&gt; and write the delimiter explicitly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;put mmn &lt;STRONG&gt;$char. '01'x&lt;/STRONG&gt; rec_seq;&lt;/PRE&gt;
&lt;P&gt;The default length of the $CHAR. format is the length of the variable it is applied to, which is probably convenient in your case (unless the defined length of MMN implies a different number of trailing spaces than you want).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2026 16:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984785#M379738</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2026-03-14T16:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Retain leading/trailing spaces while exporting SAS dataset to flat files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984787#M379739</link>
      <description>&lt;P&gt;Are you sure you don't want to write a fixed length file? Perhaps one with extra characters between the fields to make it easier for humans to read?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class;
  put name $char10. "|" sex $1. "|" age 4. "|" height 6.2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Alfred    |M|  14| 69.00
Alice     |F|  13| 56.50
Barbara   |F|  13| 65.30
Carol     |F|  14| 62.80
...&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Mar 2026 16:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-leading-trailing-spaces-while-exporting-SAS-dataset-to/m-p/984787#M379739</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-14T16:49:12Z</dc:date>
    </item>
  </channel>
</rss>

