<?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 SAS MACROS LOOP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405857#M98753</link>
    <description>&lt;P&gt;I have folders&amp;nbsp; as F_001 , F_002, F_003, F_004, F_005, F_011&lt;/P&gt;
&lt;P&gt;and each folder has Data_1 , Data_2, Data_3, Data_4, Data_5, Data_10&lt;/P&gt;
&lt;P&gt;if i give prompt x&amp;nbsp; as&amp;nbsp; 1,3,4 it should count the number of arguments in the macro x now macro x has 3 arguments so it should loop&lt;/P&gt;
&lt;P&gt;three times .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROMPT FORMAT X= 1,3,4&lt;/P&gt;
&lt;P&gt;%macro test(type);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let type = c;&lt;BR /&gt;/* first&amp;nbsp; find whether the delimiter is comma seperated&lt;/P&gt;
&lt;P&gt;%if index(&amp;amp;x,',') &amp;gt; 0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = %sysfunc(countw(&amp;amp;x,',');&lt;/P&gt;
&lt;P&gt;%do k=1 %to &amp;amp;n ; / * will loop three times one for x=1 and then x=3 and then x=4 */&lt;/P&gt;
&lt;P&gt;%let start = %substr(&amp;amp;x,&amp;amp;k,1);&lt;BR /&gt;%let end = %substr(&amp;amp;x,&amp;amp;k,1);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%do pt = &amp;amp;start %to &amp;amp;end; / * In this case&amp;nbsp; start will be 1 and end will be 1 as its looping for first time &amp;nbsp;*/&lt;BR /&gt;%let folder_name = F_00&amp;amp;pt;&lt;BR /&gt;%if &amp;amp;pt ge 10 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;%let folder_name = F_0&amp;amp;pt; /*&amp;nbsp;(here folder_name resolves to F001) */&lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;%test2(&amp;amp;folder_name,&amp;amp;type);&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please Suggest me correct syntax as above code is not working but concept is same&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 03:36:36 GMT</pubDate>
    <dc:creator>chennupriya</dc:creator>
    <dc:date>2017-10-20T03:36:36Z</dc:date>
    <item>
      <title>SAS MACROS LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405857#M98753</link>
      <description>&lt;P&gt;I have folders&amp;nbsp; as F_001 , F_002, F_003, F_004, F_005, F_011&lt;/P&gt;
&lt;P&gt;and each folder has Data_1 , Data_2, Data_3, Data_4, Data_5, Data_10&lt;/P&gt;
&lt;P&gt;if i give prompt x&amp;nbsp; as&amp;nbsp; 1,3,4 it should count the number of arguments in the macro x now macro x has 3 arguments so it should loop&lt;/P&gt;
&lt;P&gt;three times .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROMPT FORMAT X= 1,3,4&lt;/P&gt;
&lt;P&gt;%macro test(type);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let type = c;&lt;BR /&gt;/* first&amp;nbsp; find whether the delimiter is comma seperated&lt;/P&gt;
&lt;P&gt;%if index(&amp;amp;x,',') &amp;gt; 0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = %sysfunc(countw(&amp;amp;x,',');&lt;/P&gt;
&lt;P&gt;%do k=1 %to &amp;amp;n ; / * will loop three times one for x=1 and then x=3 and then x=4 */&lt;/P&gt;
&lt;P&gt;%let start = %substr(&amp;amp;x,&amp;amp;k,1);&lt;BR /&gt;%let end = %substr(&amp;amp;x,&amp;amp;k,1);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%do pt = &amp;amp;start %to &amp;amp;end; / * In this case&amp;nbsp; start will be 1 and end will be 1 as its looping for first time &amp;nbsp;*/&lt;BR /&gt;%let folder_name = F_00&amp;amp;pt;&lt;BR /&gt;%if &amp;amp;pt ge 10 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;%let folder_name = F_0&amp;amp;pt; /*&amp;nbsp;(here folder_name resolves to F001) */&lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;%test2(&amp;amp;folder_name,&amp;amp;type);&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please Suggest me correct syntax as above code is not working but concept is same&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 03:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405857#M98753</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2017-10-20T03:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405861#M98757</link>
      <description>&lt;P&gt;This seems really close to these questions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/SAS-Scan/m-p/405858/highlight/false#M98754" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/SAS-Scan/m-p/405858/highlight/false#M98754&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would also suggest looking at the Macro Appendix which now has a list of examples that may help you out.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 03:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405861#M98757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T03:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405894#M98769</link>
      <description>&lt;P&gt;To what end, what is it you want out at the end.&amp;nbsp; The reason being is that Base SAS is a really powerful language for data manipulation and can do this type of work far better than macro which only generates Base SAS code.&amp;nbsp; You you take this prompt and want to run a macro on all datasets within the given libraries.&amp;nbsp; You could go your way, or you could just say:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  do i=1 to countw("&amp;amp;x.",",");
    call execute(cats('%domacro (l=f_',put(input(scan("&amp;amp;x.",i,","),best.),z3.),');'));
  end;
run;&lt;/PRE&gt;
&lt;P&gt;This will loop over each comma delimited value in &amp;amp;x, and for each one call the macro domacro, with the parameter f_ and the value from the list.&amp;nbsp; Far simpler.&amp;nbsp; Macro is not a replacement for Base SAS!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 08:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-LOOP/m-p/405894#M98769</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-20T08:45:10Z</dc:date>
    </item>
  </channel>
</rss>

