<?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: Look up of macro variable value in file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712674#M219768</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw(filename,'&amp;amp;nl_rb.') then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use double quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you look at the &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0korze1qnq4len1mvlb5o98ht1n.htm&amp;amp;locale=en" target="_self"&gt;INDEXW&lt;/A&gt; documentation, I think it should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw("&amp;amp;nl_rb",filename,',') then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but even that doesn't work, perhaps you need to extract the fifth "word" from filename to obtain the string 0417, then it should work. Or loop through all "words" in filename.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 13:40:36 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-01-20T13:40:36Z</dc:date>
    <item>
      <title>Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712665#M219762</link>
      <description>&lt;P&gt;I'm trying to write a program to create a variable TARGET based on the file name. If the file name has value which is matched with value from the macro variable 'nl_rb' then I want if condition to statisfy otherwise else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's not happening although filename has value which is matched with the value from the macro variable 'nl_rb'. Only else statement statisfied instead of 'if'.&amp;nbsp;Any leads to understand what I was missing in 'if indexw'? Appericiate if someone of you help me understand how to look up macro variable value in the file name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample File name :&amp;nbsp; IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; %let inpath=/var/sasdata/GTM;
%let lh_path=/var/sasdata/LH;
%let nl_path=/var/sasdata/NL;

/*NL RB*/

    PROC SQL noprint;
        SELECT PARAM_VLU_TXT into: nl_rb separated by ',' 
        FROM PARAM_VLU
        WHERE CMPNT_NM = 'NL' AND PARAM_NM = 'RBK';
    QUIT;

    %put ######NL RB####### &amp;amp;nl_rb;
    /*macro variable nl_rb resolves to 0417,0437,0438,0439,0440,0441,0555,1234,0170,1100*/

    data files ;
  length id 8 msg filename source target $256 ;
  did=dopen("source");
  if did&amp;lt;=0 then do;
      msg=sysmsg(); 
      put msg; 
      stop;
  end;
  do id=1 to dnum(did);
    filename=dread(did,id);
    if scan(lowcase(filename),-1,'.')='csv' then do;
      source="&amp;amp;inpath" ||"/"|| filename;
/*check for macro variable values in filename*/
      if indexw(filename,'&amp;amp;nl_rb.') then do;
        target="&amp;amp;nl_path"||"/"||filename;
        end;
      else target="&amp;amp;lh_path"||"/"||filename;
    end;
    output;
  end;
  did=dclose(did);
  drop did msg;
run;
&lt;/PRE&gt;
&lt;P&gt;Actual Output:&lt;/P&gt;
&lt;TABLE width="804"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="72"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="354"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="161"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="217"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/GTM&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/LH&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Excepted Output:&lt;/P&gt;
&lt;TABLE width="804"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="72"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="354"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="161"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="217"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/GTM&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/NL&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712665#M219762</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T13:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712667#M219763</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;But it's not happening ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is not enough information. When code doesn't work properly, you need to show us the LOG, or the incorrect output. If you are going to show us the log, then please follow these instructions: copy the log as text and then paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon, please do not provide the log any other way.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712667#M219763</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-20T13:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712673#M219767</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actual Output:&lt;/P&gt;
&lt;TABLE width="804"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="72"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="354"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="161"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="217"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/GTM&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/LH&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Excepted Output:&lt;/P&gt;
&lt;TABLE width="804"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="72"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="354"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="161"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="217"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/GTM&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/NL&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712673#M219767</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T13:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712674#M219768</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw(filename,'&amp;amp;nl_rb.') then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use double quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you look at the &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0korze1qnq4len1mvlb5o98ht1n.htm&amp;amp;locale=en" target="_self"&gt;INDEXW&lt;/A&gt; documentation, I think it should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw("&amp;amp;nl_rb",filename,',') then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but even that doesn't work, perhaps you need to extract the fifth "word" from filename to obtain the string 0417, then it should work. Or loop through all "words" in filename.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712674#M219768</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-20T13:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712675#M219769</link>
      <description>&lt;P&gt;Did you mean:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;... If the file name has&lt;FONT size="4"&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt; a&lt;/STRONG&gt; &lt;/EM&gt;&lt;/U&gt;&lt;/FONT&gt;value which is matched with&lt;U&gt; &lt;/U&gt;&lt;FONT size="4"&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;a&lt;/STRONG&gt; &lt;/EM&gt;&lt;/U&gt;&lt;/FONT&gt;value from the macro variable 'nl_rb' then I want if condition to statisfy otherwise else.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The SCAN function is used to tokenize, that is it separates the string into its ten values, respective to the commas that delimit. the string.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;nl_rb=0417,0437,0438,0439,0440,0441,0555,1234,0170,1100;

data example;
  do i=1 to 10;
    four=scan ("&amp;amp;nl_rb", i,&lt;SPAN&gt;','&lt;/SPAN&gt;)
    output;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;more on this at this link: &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;locale=en"&gt;SAS Help Center: SCAN Function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712675#M219769</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-20T13:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712679#M219772</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;&amp;nbsp;Macro variable resolves to any number of values. It's not&amp;nbsp; upto 10 values everytime. Out of those values, any of the value will be in file name. If the filename contains the string matches with the macro value then if statement should statisfy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712679#M219772</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T13:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712680#M219773</link>
      <description>&lt;P&gt;Is it that the four digits in the filename is always positions 14 through 17?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712680#M219773</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-20T13:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712681#M219774</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Any example for this? I'm not certain to loop through all "words" in filename&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"&lt;EM&gt;but even that doesn't work, perhaps you need to extract the fifth "word" from filename to obtain the string 0417, then it should work. Or loop through all "words" in filename&lt;/EM&gt;"&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712681#M219774</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T13:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712684#M219775</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;&amp;nbsp; It's always 5th word separated by underscore '_'&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712684#M219775</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T13:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712685#M219776</link>
      <description>&lt;P&gt;then you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;four=scan(filename,5,"_");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712685#M219776</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-01-20T13:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712687#M219777</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Any example for this? I'm not certain to loop through all "words" in filename&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"&lt;EM&gt;but even that doesn't work, perhaps you need to extract the fifth "word" from filename to obtain the string 0417, then it should work. Or loop through all "words" in filename&lt;/EM&gt;"&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it's always the fifth "word", no looping is needed.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712687#M219777</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-20T13:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712688#M219778</link>
      <description>&lt;P&gt;Replace this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if indexw(filename,'&amp;amp;nl_rb.') then do;
  target="&amp;amp;nl_path"||"/"||filename;
end;
else target="&amp;amp;lh_path"||"/"||filename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = 0;
do i = 1 to countw("&amp;amp;nl_rb.",",");
  if indexw(filename,scan("&amp;amp;nl_rb.",i,",")) then flag = 1;
end;
if flag
then target="&amp;amp;nl_path"||"/"||filename;
else target="&amp;amp;lh_path"||"/"||filename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- double quotes around the macro variable&lt;/P&gt;
&lt;P&gt;- loop through the macro variable&lt;/P&gt;
&lt;P&gt;- test each "word" in the macro variable individually&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 13:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712688#M219778</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-20T13:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712692#M219780</link>
      <description>&lt;P&gt;You have two obvious problems. One is technical, macro variable references are not resolved inside of single quotes. So use double quotes.&amp;nbsp; The second is logical. The INDEXW() function cannot look for multiple possible values at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First forget the macro code aspects and figure out what SAS code you want to run. Once you have that you can think about how you could use macro code to generate that SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see a numbers of pathways.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First if the location of the "word" to check for is in the same place in the filename then reverse the arguments to the INDEXW() function. Instead of checking if the filename contains one a series of words you can pull the word you want to check from the filename and test if it is in the list of words you put into the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;indexw("&amp;amp;nl_rb",scan(filename,5,'_'),',')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could adapt your current method to use regular expression coding instead of INDEXW() function.&amp;nbsp; Play around and figure out how to use the | in regular expression to allow you to search for any one of a list of items.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other method is to split the step that gets the filenames out from the step that does the testing for the strings.&amp;nbsp; Then join the two tables and aggregate the test for the presence of each individual word from you list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select filename
     , max(0 ne indexw(filename,trim(PARAM_VLU_TXT),'_')) as any_match
  from files&amp;nbsp;
     ,&amp;nbsp;(SELECT PARAM_VLU_TXT into: nl_rb separated by ',' 
        FROM PARAM_VLU
        WHERE CMPNT_NM = 'NL' AND PARAM_NM = 'RBK') list
group by filename&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Wed, 20 Jan 2021 14:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712692#M219780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-20T14:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712710#M219788</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Still else statement statisfies. File in the source folder is - IFT_GT_RND_2_0417_1_20201009T075212.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;54         data files ;
55           length id 8 msg filename source target $256 ;
56           did=dopen("source");
57           if did&amp;lt;=0 then do;
58               msg=sysmsg();
59               put msg;
60               stop;
61           end;
62           do id=1 to dnum(did);
63             filename=dread(did,id);
64             if scan(lowcase(filename),-1,'.')='csv' then do;
65             source="&amp;amp;inpath" ||"/"|| filename;
SYMBOLGEN:  Macro variable INPATH resolves to /var/sasdata/GTM
66         
67         /*Move to NL folder*/
68               flag = 0;
69         do i = 1 to countw("&amp;amp;nl_rb.",",");
SYMBOLGEN:  Macro variable NL_RB resolves to 
            0417,0437,0438,0439,0440,0441,0555,1234,0170,1100,1101,1103,1104,1105,1400,1402,5112,5115,5116,8110,8120,8130,8190,5210,
            5440,5601,6010,6020,8040,8050,7005,7006,0169
70           if indexw(filename,scan("&amp;amp;nl_rb.",i,",")) then flag = 1;
SYMBOLGEN:  Macro variable NL_RB resolves to 
            0417,0437,0438,0439,0440,0441,0555,1234,0170,1100,1101,1103,1104,1105,1400,1402,5112,5115,5116,8110,8120,8130,8190,5210,
            5440,5601,6010,6020,8040,8050,7005,7006,0169
71         end;
72         if flag
73         then target="&amp;amp;nl_path"||"/"||filename;
SYMBOLGEN:  Macro variable NL_PATH resolves to /var/sasdata/NL
74         else target="&amp;amp;lh_path"||"/"||filename;
SYMBOLGEN:  Macro variable LH_PATH resolves to /var/sasdata/LH
75         
76             end;
77             output;
78           end;
79           did=dclose(did);                                        

80           drop did msg;
81         run;

NOTE: The data set WORK.FILES has 1 observations and 6 variables&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 14:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712710#M219788</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-20T14:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Look up of macro variable value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712718#M219795</link>
      <description>&lt;P&gt;Please internalize this:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SUCCESSFUL MACRO PROGRAMMING STARTS WITH WORKING NON-MACRO CODE!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;And also Maxim 34: Work in Steps.&lt;/P&gt;
&lt;P&gt;This would have alerted you of the fact that the INDEXW is in fact not finding what you want, and that is because you did not tell it that you use the underline as a delimiter.&lt;/P&gt;
&lt;P&gt;See this example where the string is found:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nl_rb=0417,0437,0438,0439,0440,0441,0555,1234,0170,1100;

data _null_;
filename = "IFT_GT_RND_2_0417_1_20201009T075212.csv";
flag = 0;
do i = 1 to countw("&amp;amp;nl_rb.",",");
  if indexw(filename,scan("&amp;amp;nl_rb.",i,","),"_") then flag = 1;
end;
put flag=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 73         %let nl_rb=0417,0437,0438,0439,0440,0441,0555,1234,0170,1100;
 74         
 75         data _null_;
 76         filename = "IFT_GT_RND_2_0417_1_20201009T075212.csv";
 77         flag = 0;
 78         do i = 1 to countw("&amp;amp;nl_rb.",",");
 79           if indexw(filename,scan("&amp;amp;nl_rb.",i,","),"_") then flag = 1;
 80         end;
 81         put flag=;
 82         run;
 
 flag=1
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 14:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-of-macro-variable-value-in-file-name/m-p/712718#M219795</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-20T14:47:20Z</dc:date>
    </item>
  </channel>
</rss>

