<?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: Do loop with indexw in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718533#M222391</link>
    <description>&lt;P&gt;Using temporary variable to hold the results of function-calls like &lt;FONT face="courier new,courier"&gt;scan(lowcase(filename), 5, '_')&lt;/FONT&gt; and using putlog to write the values of those variables to the log is the recommended way to debug code.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Feb 2021 11:19:22 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-02-11T11:19:22Z</dc:date>
    <item>
      <title>Do loop with indexw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718521#M222385</link>
      <description>&lt;P&gt;I've the code as below. I would like to know if there is any issue in&amp;nbsp;indexw function&amp;nbsp;under else if. I have two files in inpath and I want value of TARGET for both the records with &lt;STRONG&gt;&lt;EM&gt;flag=1&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;in output but I'm not getting any value for excel file and flag value is also 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variable NL_RB resolves to 1234,4567,7865,0098&lt;/P&gt;
&lt;P&gt;Macro variable LH_RB resolves to 0012,0013,1365,0248,7654&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Files which I kept in inpath are,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IFR_GT_MS_0012.xlsx&lt;/P&gt;
&lt;P&gt;IFR_GT_TR_1_0012_1_20201009T075212.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let function_compont=LH;
%let inpath=/var/sasdata/input/GT;
%let lh_path=/var/sasdata/input/LH;
%let nl_path=/var/sasdata/input/NL;

data files (drop= i id);
    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' or scan(lowcase(filename),-1,'.')='xlsx') and ("&amp;amp;function_compont" EQ 'NL' or "&amp;amp;function_compont" EQ 'LH') then
            do;
                source="&amp;amp;inpath" ||"/"|| filename;

                /*LH path for LH Rb*/
                if "&amp;amp;function_compont" EQ 'LH' and (scan(lowcase(filename),5,'_') not in ('5601','6010','6020')) then
                    do;
                        flag = 0;

                        do i = 1 to countw("&amp;amp;lh_rb.",",");
                            if indexw(filename,scan("&amp;amp;lh_rb.",i,","),"_") then
                                do;
                                    flag = 1;
                                    target = "&amp;amp;lh_path"||"/"||filename;
                                end;
                        end;
                    end;

                /*LH path for excel file*/
                else if "&amp;amp;function_compont" EQ 'LH' and scan(lowcase(filename),-1,'.')='xlsx' then
                    do;
                        flag = 0;

                        do i = 1 to countw("&amp;amp;lh_rb.",",");
                            if indexw(filename,scan("&amp;amp;lh_rb.",i,","),"_.") then
                                do;
                                    flag = 1;
                                    target = "&amp;amp;lh_path"||"/"||filename;
                                end;
                        end;
                    end;
                else target="&amp;amp;inpath" ||"/"|| filename;
            end;

        output;
    end;

    did=dclose(did);
    drop did msg;
run;&lt;/PRE&gt;
&lt;P&gt;Any help?&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;TABLE width="1088"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="338"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="509"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="335"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="29"&gt;&lt;STRONG&gt;flag&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="338"&gt;IFR_GT_MS_0012.xlsx&lt;/TD&gt;
&lt;TD width="509"&gt;/var/sasdata/INPUT/GT/IFR_GT_MS_0012.xlsx&lt;/TD&gt;
&lt;TD width="335"&gt;/var/sasdata/INPUT/LH/IFR_GT_MS_0012.xlsx&lt;/TD&gt;
&lt;TD width="29"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="338"&gt;IFR_GT_TR_1_0012_1_20201009T075212.csv&lt;/TD&gt;
&lt;TD width="509"&gt;/var/sasdata/INPUT/GT/IFR_GT_TR_1_0012_1_20201009T075212.csv&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 11 Feb 2021 10:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718521#M222385</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-11T10:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop with indexw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718533#M222391</link>
      <description>&lt;P&gt;Using temporary variable to hold the results of function-calls like &lt;FONT face="courier new,courier"&gt;scan(lowcase(filename), 5, '_')&lt;/FONT&gt; and using putlog to write the values of those variables to the log is the recommended way to debug code.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 11:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718533#M222391</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-11T11:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop with indexw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718541#M222397</link>
      <description>&lt;P&gt;Your code does in fact work for the csv file, but fails for the xlsx, because you missed to add the dot as delimiter in the first INDEXW function.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 11:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-with-indexw/m-p/718541#M222397</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-11T11:49:04Z</dc:date>
    </item>
  </channel>
</rss>

