<?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 search for a list of strings across files (.sas) in a library? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863090#M340949</link>
    <description>Yes, i tried your macro with more strings and it worked fine, As we are using prxmatch it returns the position of the string that we are searching for. I am looking for the name of the job (.sas) from which the string is found. The code i shared did that but couldn't search more than one string. I need the code to search for more than one string,(which your code does wonderfully) and the output should include the name of the job.</description>
    <pubDate>Wed, 08 Mar 2023 23:07:55 GMT</pubDate>
    <dc:creator>SAS_INFO</dc:creator>
    <dc:date>2023-03-08T23:07:55Z</dc:date>
    <item>
      <title>How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/862862#M340832</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to search a list of strings across sas jobs(.sas) in a library . I have used the following&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;filename abc pipe 'findstr "string" C:\Users\folder_name\*.sas 2&amp;gt;&amp;amp;1';&lt;/P&gt;&lt;P&gt;data Result;&lt;BR /&gt;infile abc truncover;&lt;BR /&gt;input ColName $200.;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=Result;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works well. But the the list of strings i have is more than 100 , so i need to use macro to pass the string. Could some one help please?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 05:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/862862#M340832</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2023-03-08T05:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/862949#M340895</link>
      <description>&lt;P&gt;Here is a technique I use that uses PRXMATCH to search for multiple strings.&amp;nbsp; Hope you find it helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro search(dir,string); &lt;BR /&gt;filename listing pipe "dir &amp;amp;dir\*.sas /b"; &lt;BR /&gt;data new; &lt;BR /&gt;infile listing truncover ; &lt;BR /&gt;input filename $80.; &lt;BR /&gt;filename="&amp;amp;dir\" || filename; &lt;BR /&gt;infile dummy filevar=filename end=done truncover; &lt;BR /&gt;do while (not done); &lt;BR /&gt;input x1 $100.; &lt;BR /&gt;&amp;nbsp; if prxmatch("m/&amp;amp;string/oi",x1) &amp;gt; 0 then output; &lt;BR /&gt;end; &lt;BR /&gt;run; &lt;BR /&gt;%mend search;&lt;/P&gt;
&lt;P&gt;/** macro and print are the two strings I am searching for.&amp;nbsp; You need the | between each string you are searching for **/&lt;BR /&gt;%search(c:\my_folder,macro|print) &lt;BR /&gt;&lt;BR /&gt;proc print; &lt;BR /&gt;run; &lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 14:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/862949#M340895</guid>
      <dc:creator>russt_sas</dc:creator>
      <dc:date>2023-03-08T14:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863018#M340910</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32726"&gt;@SAS_INFO&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I suggest a small improvement of the code supplied by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43460"&gt;@russt_sas&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;I have added three lines to the code, so the output now contains the file name and line number besides the lines containing one of the search strings.&lt;/P&gt;
&lt;P&gt;(+ changes in 2 input formats to handle longer strings based on my actual test input),&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro search(dir,string);
  filename listing pipe "dir &amp;amp;dir\*.sas /b";
  data new;
    infile listing truncover ;
    input filename &lt;FONT color="#FF0000"&gt;$255.&lt;/FONT&gt;;
    &lt;FONT color="#FF0000"&gt;file = filename;&lt;/FONT&gt;
    filename="&amp;amp;dir\" || filename;
    infile dummy filevar=filename end=done truncover;
   &lt;FONT color="#FF0000"&gt; obsnum = 0;&lt;/FONT&gt;
    do while (not done);
      input line &lt;FONT color="#FF0000"&gt;$char255.&lt;/FONT&gt;;
   &lt;FONT color="#FF0000"&gt;   obsnum + 1;&lt;/FONT&gt;
      if prxmatch("m/&amp;amp;string/oi",line) &amp;gt; 0 then output;
    end;
  run;
%mend search;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Mar 2023 15:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863018#M340910</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-08T15:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863085#M340947</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;I should be more clear . The ultimate aim of the task is to search for the list of strings among all sas jobs in a library and if any of the string is available, it should throw out the name of the job. Th code which is have posted is unable to search for more than one string at a time, while i have more than 100 string s to search. Would you please help in that.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 22:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863085#M340947</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2023-03-08T22:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863088#M340948</link>
      <description>&lt;P&gt;Not sure what you mean when you say&amp;nbsp;'&lt;SPAN&gt;unable to search for more than one string at a time'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My macro call below searches for the string 'macro' and 'print' (I could list as many strings I want here as long as it is under ~64K) :&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%search(c:\my_folder,macro|print)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 22:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863088#M340948</guid>
      <dc:creator>russt_sas</dc:creator>
      <dc:date>2023-03-08T22:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863090#M340949</link>
      <description>Yes, i tried your macro with more strings and it worked fine, As we are using prxmatch it returns the position of the string that we are searching for. I am looking for the name of the job (.sas) from which the string is found. The code i shared did that but couldn't search more than one string. I need the code to search for more than one string,(which your code does wonderfully) and the output should include the name of the job.</description>
      <pubDate>Wed, 08 Mar 2023 23:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863090#M340949</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2023-03-08T23:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863092#M340951</link>
      <description>&lt;P&gt;Doesn't the output file, new, contain a variable called filename with the filename/job name?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 23:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863092#M340951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-03-08T23:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863095#M340954</link>
      <description>No, It has only X1 as output</description>
      <pubDate>Wed, 08 Mar 2023 23:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863095#M340954</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2023-03-08T23:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a list of strings across files (.sas) in a library?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863098#M340956</link>
      <description>Eriks code modified to add the filename?</description>
      <pubDate>Wed, 08 Mar 2023 23:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-search-for-a-list-of-strings-across-files-sas-in-a/m-p/863098#M340956</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-03-08T23:45:51Z</dc:date>
    </item>
  </channel>
</rss>

