<?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: How to read 3rd field from text file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67039#M14519</link>
    <description>Nice! Thanks for this one. &lt;BR /&gt;
It really bothered me not to know how to do this.&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
    <pubDate>Fri, 12 Mar 2010 08:39:58 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2010-03-12T08:39:58Z</dc:date>
    <item>
      <title>How to read 3rd field from text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67037#M14517</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Nicole's "Reading a CSV file" reminded me that I'm having this long lasting unanswered question. &lt;BR /&gt;
&lt;BR /&gt;
I believe it's not possible but I would be happy to be told otherwise.&lt;BR /&gt;
&lt;BR /&gt;
O.K., here it comes:&lt;BR /&gt;
&lt;BR /&gt;
Have: A pipe delimited file&lt;BR /&gt;
Want: Read the 3rd column without having to map column 1 and 2 only using input statement.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile datalines dlm='|' dsd truncover;&lt;BR /&gt;
  input  VarForCol_C $;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
a1|b_1|c1&lt;BR /&gt;
a2||c2&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I know that I could do something like...&lt;BR /&gt;
...&lt;BR /&gt;
input;&lt;BR /&gt;
VarForCol_C=scan(_infile_,3,'|');&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
...but I'm wondering if I'm missing something and it could be done with some "switches" for the input statement without having to create any unnnecessary variables.&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for a generic solution which works for any number of fields(i.e. read field 15 in string with 50 fields).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 11 Mar 2010 11:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67037#M14517</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-03-11T11:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to read 3rd field from text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67038#M14518</link>
      <description>The input statement allows (variable-list) to have an N multiplier value.  I'm not sure where it is documented.  The multiplier is documented for (informat-list).  &lt;BR /&gt;
&lt;BR /&gt;
Anyway you can read a dummy variable skip n number of times.  It can be $1 so it doesn't need to read any extra data as in the example below.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
   infile datalines dlm='|' dsd truncover;&lt;BR /&gt;
   *input  VarForCol_C $;&lt;BR /&gt;
   input (2*_dummy_)(:$1.) c $;&lt;BR /&gt;
   drop _dummy_;&lt;BR /&gt;
   datalines;&lt;BR /&gt;
a1|b_1|c1&lt;BR /&gt;
a2||c2&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 11 Mar 2010 12:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67038#M14518</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-03-11T12:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to read 3rd field from text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67039#M14519</link>
      <description>Nice! Thanks for this one. &lt;BR /&gt;
It really bothered me not to know how to do this.&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 12 Mar 2010 08:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-3rd-field-from-text-file/m-p/67039#M14519</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-03-12T08:39:58Z</dc:date>
    </item>
  </channel>
</rss>

