<?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: Read CSV file conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368264#M87809</link>
    <description>&lt;P&gt;If there are always the same number of header lines then just skip them using the FIRSTOBS= option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;To skip the trailer line you can try just pre-reading the line and checking it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.dlm' dsd dlm=';' firstobs=7 truncover ;
  input @;
  if _infile_=: 'total rows' then delete;
  length Contract_Id $10 HOSTID $20 HOSTEMAIL $60 ;
  input Contract_Id HOSTID HOSTEMAIL;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the header part is variable length then just use similar method to skip over it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.dlm' dsd dlm=';' firstobs=7 truncover ;
  input @;
  if _n_=1 then do while (_infile_^=: 'Contract_Id;') ;
    input / @;
  end;
  if _infile_=: 'total rows' then delete;
  if _infile_=: 'Contract_Id;' then delete;
  length Contract_Id $10 HOSTID $20 HOSTEMAIL $60 ;
  input Contract_Id HOSTID HOSTEMAIL;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 12:19:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-06-19T12:19:45Z</dc:date>
    <item>
      <title>Read CSV file conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368245#M87796</link>
      <description>&lt;P&gt;Hi guys;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the below CSV file(DLM=';'). I want to read this file in sas datasets. The file contains lot of useless records, so we only want to read the records following the file -&amp;nbsp;&lt;SPAN&gt;Detailed Report:;; till&amp;nbsp;total rows returned:5;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;also the header will be the first record after the row- Detailed Report:;;&amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;for below file, the header is Contract_Id;HOSTID;HOSTEMAIL&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can anybody help? Thanks in advance;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Input file:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;This is a test file;created on19062017;Created by Mnjtrana&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;country-India;;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Report name:Testing;;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;email:test@test.com;;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Detailed Report:;;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Contract_Id;HOSTID;HOSTEMAIL&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;1245;bdzasd;dd@ff.dk&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;3454;bdiojk;xx@dd.com&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;3133;bdgegg;df23@dd.com&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;489;bdui3;u87@ff.com&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;2435;bdyu9k;fsf2@gh.com&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;total rows returned:5;;&lt;/STRONG&gt;&lt;/EM&gt;&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/9476i0F16A2ADEBBF0B9D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="required output" title="required output" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 11:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368245#M87796</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-06-19T11:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368248#M87798</link>
      <description>&lt;P&gt;RETAIN a flag variable in the data step, and initialize it to 0.&lt;/P&gt;
&lt;P&gt;Do a simple&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input@;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This holds the line pointer.&lt;/P&gt;
&lt;P&gt;If _infile_ contains "Detailed Report", set the flag to 1 and do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to skip to the next line.&lt;/P&gt;
&lt;P&gt;If _infile_ contains "total rows returned", set flag to 0 again.&lt;/P&gt;
&lt;P&gt;If flag is set, read the line as intended. Use @1 to start from the beginning of the line.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 11:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368248#M87798</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-19T11:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368250#M87800</link>
      <description>&lt;P&gt;Sorry, have to say it, that is not a CSV (Comma Separated Varible file) it is a delimited file. &amp;nbsp;Its not even a real delimited file, you have multiple delimited files in one. &amp;nbsp;As read is sequential, most techniques will still have to read the data, wether they output it to the dataset or not is a different matter. &amp;nbsp;Personally I would go back to the author and ask then to fix it, either by providing correctly formatted files for each section, or in a format which can handle multiple datasets such as XML. &amp;nbsp;Alternatively you can write your own file processor (i.e. you write maintain, validate etc.) following the advice given by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 11:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368250#M87800</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-19T11:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368260#M87806</link>
      <description>sorry my bad, this is a delimited file and yes it contains multiple type of data.&lt;BR /&gt;Changing the content of this file is not possible, already checked with the author. I will try th solution given by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;</description>
      <pubDate>Mon, 19 Jun 2017 12:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368260#M87806</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-06-19T12:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368264#M87809</link>
      <description>&lt;P&gt;If there are always the same number of header lines then just skip them using the FIRSTOBS= option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;To skip the trailer line you can try just pre-reading the line and checking it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.dlm' dsd dlm=';' firstobs=7 truncover ;
  input @;
  if _infile_=: 'total rows' then delete;
  length Contract_Id $10 HOSTID $20 HOSTEMAIL $60 ;
  input Contract_Id HOSTID HOSTEMAIL;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the header part is variable length then just use similar method to skip over it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile.dlm' dsd dlm=';' firstobs=7 truncover ;
  input @;
  if _n_=1 then do while (_infile_^=: 'Contract_Id;') ;
    input / @;
  end;
  if _infile_=: 'total rows' then delete;
  if _infile_=: 'Contract_Id;' then delete;
  length Contract_Id $10 HOSTID $20 HOSTEMAIL $60 ;
  input Contract_Id HOSTID HOSTEMAIL;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 12:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-conditionally/m-p/368264#M87809</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-19T12:19:45Z</dc:date>
    </item>
  </channel>
</rss>

