<?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: Output work file named based on macro loop iteration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399006#M278457</link>
    <description>&lt;P&gt;Try addapt the macro as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO LOOP;
%DO I = 1 %TO 1;
%DO J = 1 %TO 1;
 
*CALCULATIONS AND STEPS IN HERE;
&lt;BR /&gt;/* calculate previous I, J values */ 
%let m = &amp;amp;i;
%let n = &amp;amp;j;
%if &amp;amp;n &amp;gt; 1 %then %let n = %eval(&amp;amp;n - 1); 
%else %do;
      %if &amp;amp;i &amp;gt; 1 %then %do;
            %let n = %TO;
            %let m = %eval(&amp;amp;i -1);
      %end;
%end;

DATA HAVE&amp;amp;i&amp;amp;j;
%if &amp;amp;i=1 and &amp;amp;j=1 %then %do; SET HAVE; %end;
%else %do; SET HAVE&amp;amp;m&amp;amp;n; %end;

*CALCULATIONS IN HERE
RUN; QUIT;
 
%END;
%END;
%MEND LOOP;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 27 Sep 2017 02:56:48 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-09-27T02:56:48Z</dc:date>
    <item>
      <title>Output work file named based on macro loop iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399002#M278456</link>
      <description>&lt;P&gt;Hi there,&lt;BR /&gt;&lt;BR /&gt;I have a double nested macro loop and at the end of each iteration I want to output the resulting work file and at the same time have it named so that I know which iteration of each loop it is at. I can do it so that I have either &amp;amp;I or &amp;amp;J in the name but not both...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Code looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO LOOP;&lt;BR /&gt;%DO I = 1 %TO 1;&lt;BR /&gt;%DO J = 1 %TO 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*CALCULATIONS AND STEPS IN HERE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;*CALCULATIONS IN HERE&lt;BR /&gt;RUN; QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%END;&lt;BR /&gt;%END;&lt;BR /&gt;%MEND LOOP;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I want is multiple output files (using the data I have after each loop) that are named "LOOP_-1_+1", "LOOP_-3_+2" etc...&lt;BR /&gt;&lt;BR /&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 02:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399002#M278456</guid>
      <dc:creator>Tyler_G</dc:creator>
      <dc:date>2017-09-27T02:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Output work file named based on macro loop iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399006#M278457</link>
      <description>&lt;P&gt;Try addapt the macro as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO LOOP;
%DO I = 1 %TO 1;
%DO J = 1 %TO 1;
 
*CALCULATIONS AND STEPS IN HERE;
&lt;BR /&gt;/* calculate previous I, J values */ 
%let m = &amp;amp;i;
%let n = &amp;amp;j;
%if &amp;amp;n &amp;gt; 1 %then %let n = %eval(&amp;amp;n - 1); 
%else %do;
      %if &amp;amp;i &amp;gt; 1 %then %do;
            %let n = %TO;
            %let m = %eval(&amp;amp;i -1);
      %end;
%end;

DATA HAVE&amp;amp;i&amp;amp;j;
%if &amp;amp;i=1 and &amp;amp;j=1 %then %do; SET HAVE; %end;
%else %do; SET HAVE&amp;amp;m&amp;amp;n; %end;

*CALCULATIONS IN HERE
RUN; QUIT;
 
%END;
%END;
%MEND LOOP;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Sep 2017 02:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399006#M278457</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-09-27T02:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Output work file named based on macro loop iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399020#M278458</link>
      <description>&lt;P&gt;You can't have negatives and positives in your names. You can include them in the labels if you want.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 04:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399020#M278458</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-27T04:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Output work file named based on macro loop iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399096#M278459</link>
      <description>&lt;P&gt;Because your loop re-uses HAVE, the easiest way would be to copy over the output at the end of the loop.&amp;nbsp; Instead of a QUIT statement, replace that with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data loop_&amp;amp;i._&amp;amp;j.;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**********************************&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDITED:&amp;nbsp; An even better idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really, you only need to change one line of code.&amp;nbsp; Right now your program includes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change this line to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have loop_&amp;amp;i._&amp;amp;j.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399096#M278459</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-27T14:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Output work file named based on macro loop iteration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399674#M278460</link>
      <description>&lt;P&gt;Worked perfectlyI Thanks! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 01:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-work-file-named-based-on-macro-loop-iteration/m-p/399674#M278460</guid>
      <dc:creator>Tyler_G</dc:creator>
      <dc:date>2017-09-29T01:38:09Z</dc:date>
    </item>
  </channel>
</rss>

