<?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: Text File Creation in DI in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322952#M271138</link>
    <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i understood correctly, you want to ass header and footer to your file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the FILE and put statement to write the header in the file and you can use the below code to write to the file.&lt;/P&gt;
&lt;P&gt;But you need to remove the REPLACE option, as that would delete your file(and the header too).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the file is exported through proc export, you can open the file again and using option- MOD( its opens the file and append contents to the end of the file), See an example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _null_;
file out mod;
put "------your footer here ----";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jan 2017 04:32:01 GMT</pubDate>
    <dc:creator>mnjtrana</dc:creator>
    <dc:date>2017-01-09T04:32:01Z</dc:date>
    <item>
      <title>Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322931#M271137</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a text file using user written code.&lt;/P&gt;&lt;P&gt;What I need to do is have a line at the top of the text file up to 100 characters.&lt;/P&gt;&lt;P&gt;Then I need to output my main data which could consist of a few thousand rows, which I am using the below code for.&lt;/P&gt;&lt;P&gt;PROC PRINT DATA=TCMPROC.TEST;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC EXPORT DATA=TCMPROC.TEST&lt;BR /&gt;OUTFILE="\\C:\invoice_names.txt"&lt;BR /&gt;DBMS=TAB REPLACE;&lt;BR /&gt;PUTNAMES=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then at the end of the file I need another line of data around 100 characters long to finish the text file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I go about merging a unique header and footer record around the main data that I have by building on the code above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aidan&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 11:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322931#M271137</guid>
      <dc:creator>Aidan</dc:creator>
      <dc:date>2017-01-06T11:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322952#M271138</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i understood correctly, you want to ass header and footer to your file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the FILE and put statement to write the header in the file and you can use the below code to write to the file.&lt;/P&gt;
&lt;P&gt;But you need to remove the REPLACE option, as that would delete your file(and the header too).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the file is exported through proc export, you can open the file again and using option- MOD( its opens the file and append contents to the end of the file), See an example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _null_;
file out mod;
put "------your footer here ----";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 04:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322952#M271138</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-09T04:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322953#M271139</link>
      <description>Thank you I will try this today and let you know how it goes</description>
      <pubDate>Fri, 06 Jan 2017 12:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322953#M271139</guid>
      <dc:creator>Aidan</dc:creator>
      <dc:date>2017-01-06T12:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322982#M271140</link>
      <description>In some environments all files are required to have header/footers. If this is the case for you, I would invest some time in creating a User Written Transformation instead, so you caneed reuse this logic.</description>
      <pubDate>Fri, 06 Jan 2017 14:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/322982#M271140</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-01-06T14:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323100#M271141</link>
      <description>&lt;P&gt;It's good practice with DIS&amp;nbsp;to avoid user written code as far as possible. I totally understand that this is not always feasable - but we can at least try.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you could do is to have a pre-process implemented as user written code or as user transformation if you need this more than once and only write the header, then use a normal File Writer and add 'mod' under options so that the additional output gets appended to the external file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6626i393BC54E42A47AA5/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my working example I'm using the following code in the User Written transformation&amp;nbsp;(Code generation mode: User written body):&lt;/P&gt;
&lt;PRE&gt;data _null_;&lt;BR /&gt; file "&amp;amp;_OUTPUT";&lt;BR /&gt; put "--- my header line here ----";&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;And then in the File Writer:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6625i86CB01EB90503CF6/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which creates&amp;nbsp;the following output:&lt;/P&gt;
&lt;PRE&gt;--- my header line here ----
"Alfred","M","14","69","112.5"
"Alice","F","13","56.5","84"
"Barbara","F","13","65.3","98"&lt;BR /&gt;.....&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 22:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323100#M271141</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-06T22:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323104#M271142</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34466"&gt;@mnjtrana&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I believe your code should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _null_;
  file out mod;
  put "------your footer here ----";
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jan 2017 22:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323104#M271142</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-06T22:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323250#M271143</link>
      <description>&lt;P&gt;Thanks, you are right.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 04:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323250#M271143</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-09T04:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Text File Creation in DI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323298#M271144</link>
      <description>Thank you for this, works very well with what I need.</description>
      <pubDate>Mon, 09 Jan 2017 09:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-File-Creation-in-DI/m-p/323298#M271144</guid>
      <dc:creator>Aidan</dc:creator>
      <dc:date>2017-01-09T09:30:34Z</dc:date>
    </item>
  </channel>
</rss>

