<?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: testing if unstructured text file contains a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477515#M123003</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This code will search text files for a single word, search_string
Originally via @schmuel here:
https://communities.sas.com/t5/Base-SAS-Programming/Searching-SAS-code-for-keywords/m-p/390472#M93671
*/

%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&amp;amp;root.sas_help/*.&amp;amp;suffix"); 

data results;
     length fname _filepath $200;
     infile finp filename = _filepath eov=_eov truncover;
     input a_line $200.;
     fname = _filepath;
     
     if _eov=1 then do;
       _n=0;

       _eov=0;
     end;
     _n+1;
     
     if find(a_line,"&amp;amp;search_string",'i')
     then output;
     keep _n a_line fname;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/103008"&gt;@desertsp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to determine if an unstructured text-file&amp;nbsp;contains a specific string. This is different than the usual objective when reading a file (creating dataset records). Is it possible to simply read the entire file into&amp;nbsp;one long&amp;nbsp;string which could&amp;nbsp;be parsed using FIND()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone please&amp;nbsp;suggest the proper way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW - the file is a log generated by another application, and I'll be searching for a short alphanumeric (&amp;lt;20&amp;nbsp;bytes)&amp;nbsp;string consisting of only numbers 0-9 and letters A-Z. The string may be surrounded by whitespace or other symbols. Performance is not a consideration, and it would be exceedingly rare for the log-file to exceed more than a few hundred KB. Additionally, it will be rare that the string is not found in the first line of the file, however that is not guaranteed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jul 2018 14:42:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-12T14:42:54Z</dc:date>
    <item>
      <title>testing if unstructured text file contains a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477495#M122996</link>
      <description>&lt;P&gt;I need to determine if an unstructured text-file&amp;nbsp;contains a specific string. This is different than the usual objective when reading a file (creating dataset records). Is it possible to simply read the entire file into&amp;nbsp;one long&amp;nbsp;string which could&amp;nbsp;be parsed using FIND()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone please&amp;nbsp;suggest the proper way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW - the file is a log generated by another application, and I'll be searching for a short alphanumeric (&amp;lt;20&amp;nbsp;bytes)&amp;nbsp;string consisting of only numbers 0-9 and letters A-Z. The string may be surrounded by whitespace or other symbols. Performance is not a consideration, and it would be exceedingly rare for the log-file to exceed more than a few hundred KB. Additionally, it will be rare that the string is not found in the first line of the file, however that is not guaranteed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 14:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477495#M122996</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-07-12T14:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: testing if unstructured text file contains a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477515#M123003</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This code will search text files for a single word, search_string
Originally via @schmuel here:
https://communities.sas.com/t5/Base-SAS-Programming/Searching-SAS-code-for-keywords/m-p/390472#M93671
*/

%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&amp;amp;root.sas_help/*.&amp;amp;suffix"); 

data results;
     length fname _filepath $200;
     infile finp filename = _filepath eov=_eov truncover;
     input a_line $200.;
     fname = _filepath;
     
     if _eov=1 then do;
       _n=0;

       _eov=0;
     end;
     _n+1;
     
     if find(a_line,"&amp;amp;search_string",'i')
     then output;
     keep _n a_line fname;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/103008"&gt;@desertsp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to determine if an unstructured text-file&amp;nbsp;contains a specific string. This is different than the usual objective when reading a file (creating dataset records). Is it possible to simply read the entire file into&amp;nbsp;one long&amp;nbsp;string which could&amp;nbsp;be parsed using FIND()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone please&amp;nbsp;suggest the proper way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW - the file is a log generated by another application, and I'll be searching for a short alphanumeric (&amp;lt;20&amp;nbsp;bytes)&amp;nbsp;string consisting of only numbers 0-9 and letters A-Z. The string may be surrounded by whitespace or other symbols. Performance is not a consideration, and it would be exceedingly rare for the log-file to exceed more than a few hundred KB. Additionally, it will be rare that the string is not found in the first line of the file, however that is not guaranteed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 14:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477515#M123003</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-12T14:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: testing if unstructured text file contains a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477534#M123007</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is exactly what I need.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/testing-if-unstructured-text-file-contains-a-string/m-p/477534#M123007</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-07-12T15:10:15Z</dc:date>
    </item>
  </channel>
</rss>

