<?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: Inserting datalines into file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417423#M280348</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163649"&gt;@Autotelic&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Actually what I want is to export a dataset as a semicolon separated value text file, only&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;on top of the dataset headers, I need to add two semicolon separated row of values, the first one is a row of headers, the second one is a row of values for the first header.&lt;/LI&gt;
&lt;LI&gt;the bottom of the csv&amp;nbsp;has the same structure as the dataset and are datalines which I want to be able to customize in code&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I then want to output the result of this as a text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this way of phrasing things make it any simpler?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is trivial to write a delimited file using a data step. Just use the DSD= and DLM= option on the FILE statement and write the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'myfile.txt' dsd dlm=';' ;
put a b c ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to write extra information at the top then add and IF _N_=1 THEN DO;... END; block to the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _n_=1 then do;
  put 'header1';
  put x1 x2 x3 ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does the "bottom" of the file include a new header row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please post an example dataset (in the form of a data step that we can run to create the example data) .&amp;nbsp; Also include source for the information you want to put in the first two lines.&amp;nbsp; Then show an example of the&amp;nbsp;output you want to create from that sample data.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2017 15:23:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-11-30T15:23:11Z</dc:date>
    <item>
      <title>Inserting datalines into file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417374#M280344</link>
      <description>&lt;P&gt;How does one go about adding datalines to an existing text file?&lt;/P&gt;&lt;P&gt;I'm on SAS 9.4, SAS EG 7.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following (copied from somewhere), but I can't adapt it to what I need.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   file "file_path_name" mod;
  input fruit :$10.;
  put fruit;
datalines;
date
elderberry
fig
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to append semicolon separated values both to the start and to the end of the file.&lt;/P&gt;&lt;P&gt;As an example assume that &lt;EM&gt;file_path_name&amp;nbsp;&lt;/EM&gt;looks like this:&lt;/P&gt;&lt;PRE&gt;1;2;a
2;2;b&lt;/PRE&gt;&lt;P&gt;And I want to add&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;0;;&lt;/PRE&gt;&lt;P&gt;to the top of the file and&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;2;3;c&lt;/PRE&gt;&lt;P&gt;to the end of the file.&lt;/P&gt;&lt;P&gt;These lines should be present in code and not in another file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do this?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 11:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417374#M280344</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-11-30T11:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting datalines into file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417392#M280345</link>
      <description>&lt;P&gt;You cant really mod a file to add text at the beginning, you read it then write it out, something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set yourdata;
  infile "your_file";
  file "your_file";
  /* Put first update */
  if _n_=1 then do;
    put xyz;
  end;
  input;
  put _input_;
  /* Put end update */
  if eof then do;
    put ...;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;I suppose the question would be why would you need to , you can just append your data, then the reading program would sort it anyways.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 13:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417392#M280345</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-30T13:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting datalines into file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417411#M280346</link>
      <description>&lt;P&gt;Actually what I want is to export a dataset as a semicolon separated value text file, only&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;on top of the dataset headers, I need to add two semicolon separated row of values, the first one is a row of headers, the second one is a row of values for the first header.&lt;/LI&gt;&lt;LI&gt;the bottom of the csv&amp;nbsp;has the same structure as the dataset and are datalines which I want to be able to customize in code&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I then want to output the result of this as a text file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this way of phrasing things make it any simpler?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 14:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417411#M280346</guid>
      <dc:creator>Autotelic</dc:creator>
      <dc:date>2017-11-30T14:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting datalines into file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417418#M280347</link>
      <description>&lt;P&gt;Well, firstly, and most important, delimiting a file with a semicolon and then calling it a csv doesn't work.&amp;nbsp; CSV stands for &lt;U&gt;&lt;STRONG&gt;Comma&lt;/STRONG&gt; &lt;/U&gt;Separated Variable file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your question, simplest way would be to read in the data as it stands, write (or copy from a proc import in the log) a datastep import&amp;nbsp;(using infile) of the data as it stands.&amp;nbsp; Then with your dataset add the extra row(s) you need to the dataset - this means you can use all the SAS formats and such like.&amp;nbsp; Then once you have your final data, output this to delimited file (*.txt), using a datastep with a file command.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 15:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417418#M280347</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-30T15:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting datalines into file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417423#M280348</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163649"&gt;@Autotelic&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Actually what I want is to export a dataset as a semicolon separated value text file, only&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;on top of the dataset headers, I need to add two semicolon separated row of values, the first one is a row of headers, the second one is a row of values for the first header.&lt;/LI&gt;
&lt;LI&gt;the bottom of the csv&amp;nbsp;has the same structure as the dataset and are datalines which I want to be able to customize in code&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I then want to output the result of this as a text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this way of phrasing things make it any simpler?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is trivial to write a delimited file using a data step. Just use the DSD= and DLM= option on the FILE statement and write the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'myfile.txt' dsd dlm=';' ;
put a b c ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to write extra information at the top then add and IF _N_=1 THEN DO;... END; block to the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _n_=1 then do;
  put 'header1';
  put x1 x2 x3 ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does the "bottom" of the file include a new header row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Please post an example dataset (in the form of a data step that we can run to create the example data) .&amp;nbsp; Also include source for the information you want to put in the first two lines.&amp;nbsp; Then show an example of the&amp;nbsp;output you want to create from that sample data.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 15:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-datalines-into-file/m-p/417423#M280348</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-30T15:23:11Z</dc:date>
    </item>
  </channel>
</rss>

