<?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: Looping the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484190#M125674</link>
    <description>Yes, use the search facility. It has been explained so many times that another repetition is useless. Remember that before you start creating a macro it is wise to have working code.</description>
    <pubDate>Sun, 05 Aug 2018 17:54:51 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2018-08-05T17:54:51Z</dc:date>
    <item>
      <title>Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484188#M125672</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have this macro which I need to repeat multiple times so want to loop it instead.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Sample 1:&lt;BR /&gt;&lt;BR /&gt;%macro check_list;&lt;BR /&gt;%global list1;&lt;BR /&gt;%if list1= % then %do;&lt;BR /&gt;%let list1=“myname”;&lt;BR /&gt;&lt;BR /&gt;....&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend check_list;&lt;BR /&gt;%check_list;&lt;BR /&gt;&lt;BR /&gt;Data test1;&lt;BR /&gt;Set list1;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I need to repeat the same code for list2, list3 and list4 and also create data1, data2 , data3, data4.&lt;BR /&gt;&lt;BR /&gt;I tried to wrap the sample1 Code using.&lt;BR /&gt;%macro loop;&lt;BR /&gt;%do i = 1 %to 4;&lt;BR /&gt;&lt;BR /&gt;Sample1(replaced list1 with list&amp;amp; and data1 with data&amp;amp;i)&lt;BR /&gt;&lt;BR /&gt;Error: Attempt to %global a name(list2) which exists in a local environment.&lt;BR /&gt;&lt;BR /&gt;Any suggestions ?&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Aug 2018 17:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484188#M125672</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-08-05T17:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484189#M125673</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Any suggestions ?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, show us the actual code and SASLOG that you are using. Run the code again with OPTIONS MPRINT; as the first line and then paste the SASLOG into the {i} window; and paste the actual code into the running man window.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 18:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484189#M125673</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-05T18:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484190#M125674</link>
      <description>Yes, use the search facility. It has been explained so many times that another repetition is useless. Remember that before you start creating a macro it is wise to have working code.</description>
      <pubDate>Sun, 05 Aug 2018 17:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484190#M125674</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-08-05T17:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484209#M125682</link>
      <description>&lt;P&gt;You don't need a global macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your code is&amp;nbsp;as basic as in your example then just wrap it in a macro with a %do loop. e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_list;
  %do i=1 %to 4;
    Data test&amp;amp;i;
      Set list&amp;amp;i.;
    Run;
  %end;
%mend;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 21:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484209#M125682</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-05T21:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484225#M125690</link>
      <description>&lt;P&gt;Somehow, your code creates a local macro variable named LIST2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But nobody can help beyond that.&amp;nbsp; It's in your macro code somewhere, and only you can see that code.&amp;nbsp; If you were to share it, you might get a more specific answer.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 23:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484225#M125690</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-05T23:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484433#M125772</link>
      <description>&lt;P&gt;Do you really need list1 to be global?&lt;/P&gt;
&lt;P&gt;Also you can create the macro such that a parameter that you do not explicitly assign has a default value:&lt;/P&gt;
&lt;P&gt;Instead of : %macro check_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use: %macro(List1=myname);&lt;/P&gt;
&lt;P&gt;the Default value of LIST1 inside the macro then becomes myname.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be extremely careful of quotes as part of macro variables. Often they make coding much harder. The actual code and how LIST1 is used outside of the macro would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 16:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-the-macro/m-p/484433#M125772</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-06T16:17:58Z</dc:date>
    </item>
  </channel>
</rss>

