<?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: Appending to an external file with a &amp;quot;trailer record&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155369#M30426</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An untested template example of my last suggestion:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; file 'your-file-name';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile 'your-file-name' end=lastrec;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if lastrec then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-1';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-2';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-3';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put _infile_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 May 2014 17:03:08 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2014-05-12T17:03:08Z</dc:date>
    <item>
      <title>Appending to an external file with a "trailer record"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155366#M30423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to append data to an external file which has a "trailer record".&amp;nbsp;&amp;nbsp; That means that what I want to "append" really needs to be inserted just before that record.&amp;nbsp; &lt;BR /&gt;It's not HTML - but imagine if you needed to update an HTML file by inserting records prior to the &amp;lt;/BODY&amp;gt; tag.&amp;nbsp; It's a similar concept.&lt;/P&gt;&lt;P&gt;What I've come up with so far is kludgy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Using DATA_NULL_,&amp;nbsp; INFILE referencing the original, and FILE referencing a temporary file,&amp;nbsp; copy all of the records except the trailer to a temporary file.&lt;/P&gt;&lt;P&gt;2. Using DATA_NULL_ and FILE referencing the temporary file with MOD, write the new records and then a trailer record&lt;BR /&gt;3. Using DATA _NULL_, INFILE referencing the temporary file and FILE referencing the original, copy all of the (updated) records from temporary to original&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's got to be a better way?&amp;nbsp; And hopefully without risk of losing the records (although I will build in a backup)&lt;/P&gt;&lt;P&gt;Environment note:&amp;nbsp; this is a text-type file within a Unix directory on a z/OS system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 May 2014 16:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155366#M30423</guid>
      <dc:creator>TimH</dc:creator>
      <dc:date>2014-05-12T16:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to an external file with a "trailer record"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155367#M30424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;1. Read original file into a SAS data set&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2. Use set statement with end= option to write the data to the original file inserting the new records when the end= variable is 1, followed by the trailer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 May 2014 16:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155367#M30424</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2014-05-12T16:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to an external file with a "trailer record"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155368#M30425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, you should be able to just do it in one data step by reading the external file with the end= option writing out to the same external file. When the end= variable is 1 write the extra records followed by the trailer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 May 2014 16:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155368#M30425</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2014-05-12T16:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to an external file with a "trailer record"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155369#M30426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An untested template example of my last suggestion:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; file 'your-file-name';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile 'your-file-name' end=lastrec;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if lastrec then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-1';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-2';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'new-rec-3';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put _infile_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 May 2014 17:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155369#M30426</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2014-05-12T17:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to an external file with a "trailer record"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155370#M30427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, your last example works &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 May 2014 19:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-an-external-file-with-a-quot-trailer-record-quot/m-p/155370#M30427</guid>
      <dc:creator>TimH</dc:creator>
      <dc:date>2014-05-12T19:48:11Z</dc:date>
    </item>
  </channel>
</rss>

