<?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 trailing spaces in fixed width file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520209#M141032</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put lines $4000.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;just use formatted output.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Dec 2018 00:01:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-12-11T00:01:38Z</dc:date>
    <item>
      <title>Retain trailing spaces in fixed width file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520207#M141030</link>
      <description>&lt;P&gt;I'm trying to extract a subset of records from a fixed-width data file using an infile statement and looking for the substring '2018' at a specific location.&amp;nbsp; My goal is to output the matching records into the same fixed-width file format from which they were extracted.&amp;nbsp; However, the original file contains records in a fixed-width 4000 character string with the last 989 characters as padded spaces.&amp;nbsp; No matter what I do I can't seem to retain the padded spaces at the end.&amp;nbsp; The resulting data file (temp.txt) has records that end at position 3019.&amp;nbsp; How do I retain the padded spaces in the new file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To be clear, I can import both the original and created fixed-width files into SAS using the same import code.&amp;nbsp; That's not my goal.&amp;nbsp; My goal is to retain the padded spaces so the file will be recognized as the acceptable file format by the system to which it is submitted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;&lt;BR /&gt;	missing;
  	infile "C:\TEMP\fixed_width_4000.txt" lrecl=4000 truncover;
  	input lines  $1-4000; 

	if substr(lines,1,4) eq '2018';
run;

Options noQuoteLenMax;
data _null_;
	set test;
	file "C:\TEMP\temp.txt" lrecl=4000 n=4 MOD;
	put lines;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 23:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520207#M141030</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-12-10T23:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retain trailing spaces in fixed width file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520208#M141031</link>
      <description>&lt;P&gt;First thing, congratulations on not destroying your original file. I was afraid you going to use the same in and out file name with potential disaster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simplest might be to add the PAD option to your file statement.&lt;/P&gt;
&lt;PRE&gt;data _null_;
	set test;
	file "C:\TEMP\temp.txt" lrecl=4000 n=4 MOD PAD;
	put lines;
run;&lt;/PRE&gt;
&lt;P&gt;I assume that you are using MOD for testing as your final result doesn't want the previous short lines plus the correct lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 00:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520208#M141031</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-11T00:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Retain trailing spaces in fixed width file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520209#M141032</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put lines $4000.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;just use formatted output.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 00:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520209#M141032</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-11T00:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retain trailing spaces in fixed width file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520369#M141087</link>
      <description>&lt;P&gt;Use the $CHAR informat/format to preserve leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "C:\TEMP\fixed_width_4000.txt" lrecl=4000 truncover;
  file "C:\TEMP\updated.txt" lrecl=4000 ;
  input lines  $char4000.; 
  if substr(lines,1,4) eq '2018';
  put lines $char4000.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just use the _INFILE_ automatic variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "C:\TEMP\fixed_width_4000.txt" lrecl=4000 truncover;
  file "C:\TEMP\updated.txt" lrecl=4000 ;
  input ;
  if substr_infile_,1,4) eq '2018';
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 14:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-trailing-spaces-in-fixed-width-file/m-p/520369#M141087</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-11T14:18:05Z</dc:date>
    </item>
  </channel>
</rss>

