<?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: Search string in text file to find row to import from in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624464#M183971</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/166093"&gt;@TobbeNord&lt;/a&gt;&amp;nbsp; To address&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;'It should start import the row &lt;STRONG&gt;below&lt;/STRONG&gt; "sleep stage" .'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an ELSE as shown below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; if not _dataFound then do;
      input @;
      _dataFound = find(_infile_, 'Sleep Stage') &amp;gt; 0;
    end;
    else
	if _dataFound then do;
		input Sleep $ Position :$10. Time :$8. event :$20. Duration :8.;
		output;
	end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Feb 2020 13:07:36 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-13T13:07:36Z</dc:date>
    <item>
      <title>Search string in text file to find row to import from</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624453#M183964</link>
      <description>&lt;P&gt;I have several hundreds of tab delimited text files and the data I want to import starts in different rows for each text file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data starts at the row after the word "Sleep Stage" .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I somehow search for this string in my infile statement? In this example code the data starts at row 205 , but it can vary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro import_file(path, file_name, dataset_name);&lt;/P&gt;&lt;P&gt;data &amp;amp;dataset_name.;&lt;BR /&gt;infile "&amp;amp;path.\&amp;amp;file_name." DSD DLM="09"x firstobs=205;&lt;BR /&gt;input Sleep $ Position :$10. Time :$8. event :$20. Duration :8.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 12:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624453#M183964</guid>
      <dc:creator>TobbeNord</dc:creator>
      <dc:date>2020-02-13T12:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Search string in text file to find row to import from</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624458#M183968</link>
      <description>&lt;P&gt;Searching with the infile-statement is not possible. I would use two input statement (untested code):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_file(path, file_name, dataset_name);
  data &amp;amp;dataset_name.;
    length _dataFound 8;
    retain _dataFound 0;
	drop _dataFound;
	
    infile "&amp;amp;path.\&amp;amp;file_name." DSD DLM="09"x;

    if not _dataFound then do;
      input @;
      _dataFound = find(_infile_, 'Sleep Stage') &amp;gt; 0;
    end;

	if _dataFound then do;
		input Sleep $ Position :$10. Time :$8. event :$20. Duration :8.;
		output;
	end;
  run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: remove firstobs from infile &lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 12:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624458#M183968</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-02-13T12:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Search string in text file to find row to import from</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624460#M183969</link>
      <description>Thank you!&lt;BR /&gt;It almost worked as wanted.&lt;BR /&gt;The only little "bug" is that it also import the row with "sleep stage" on it.&lt;BR /&gt;It should start import the row below "sleep stage" .</description>
      <pubDate>Thu, 13 Feb 2020 12:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624460#M183969</guid>
      <dc:creator>TobbeNord</dc:creator>
      <dc:date>2020-02-13T12:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Search string in text file to find row to import from</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624464#M183971</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/166093"&gt;@TobbeNord&lt;/a&gt;&amp;nbsp; To address&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;'It should start import the row &lt;STRONG&gt;below&lt;/STRONG&gt; "sleep stage" .'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an ELSE as shown below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; if not _dataFound then do;
      input @;
      _dataFound = find(_infile_, 'Sleep Stage') &amp;gt; 0;
    end;
    else
	if _dataFound then do;
		input Sleep $ Position :$10. Time :$8. event :$20. Duration :8.;
		output;
	end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Feb 2020 13:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624464#M183971</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-13T13:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Search string in text file to find row to import from</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624477#M183977</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The data starts at the row after the word "Sleep Stage" .&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So just read lines until you find it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dataset_name.;
  infile "&amp;amp;path.\&amp;amp;file_name." DSD DLM="09"x ;
  if _n_=1 then do until (upcase(_infile_) contains 'SLEEP STAGE');
    input;
  end;
  input Sleep $ Position :$10. Time :$8. event :$20. Duration :8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Feb 2020 14:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-string-in-text-file-to-find-row-to-import-from/m-p/624477#M183977</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-13T14:22:47Z</dc:date>
    </item>
  </channel>
</rss>

