<?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: Conditional iteration - how can I leave the macro at the end? in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783999#M25497</link>
    <description>&lt;P&gt;I tried your method and it worked (I had to add % to 'then' though.). Thank you. Can I ask you one more thing?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a section above hosp_2more_timeframe1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the program iterate until it finds ed_2more_timeframe1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once ed_2more_timeframe1 is found, it should go to the next section to find hosp_2more_timeframe1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not think the first %if &amp;amp;stop = yes %then %let i = 3000 works.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_0-1638558947633.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66390i6E1C024737E04048/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_0-1638558947633.png" alt="Yoko_0-1638558947633.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Dec 2021 19:19:04 GMT</pubDate>
    <dc:creator>Yoko</dc:creator>
    <dc:date>2021-12-03T19:19:04Z</dc:date>
    <item>
      <title>Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783976#M25493</link>
      <description>&lt;P&gt;I created a macro with iteration of 3000. The first part looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_0-1638553465078.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66386i17D02755976E6FB0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_0-1638553465078.png" alt="Yoko_0-1638553465078.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The last part looks like this (there are more codes between these):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_2-1638553531920.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66388i267BA6491C94BB81/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_2-1638553531920.png" alt="Yoko_2-1638553531920.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to end the iteration at the end if hosp_2more_timeframe1 = 1, and want to keep going if it's not 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yoko&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;</description>
      <pubDate>Fri, 03 Dec 2021 17:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783976#M25493</guid>
      <dc:creator>Yoko</dc:creator>
      <dc:date>2021-12-03T17:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783977#M25494</link>
      <description>&lt;P&gt;Some options:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create a macro variable to store the value of the hosp_2more_timeframe1.&lt;/LI&gt;
&lt;LI&gt;Change your %DO to a %DO + %WHILE/%UNTIL loop&lt;/LI&gt;
&lt;LI&gt;or add an %IF/%THEN to check if the loop should run and add a %LEAVE &lt;BR /&gt;&lt;BR /&gt;%WHILE&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0kqh50asw98oyn18n5motyx4bpz.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0kqh50asw98oyn18n5motyx4bpz.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;%UNTIL&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1838snxda3yvhn1o0jg6bnv5xyw.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1838snxda3yvhn1o0jg6bnv5xyw.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;%IF/%THEN&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n18fij8dqsue9pn1lp8436e5mvb7.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n18fij8dqsue9pn1lp8436e5mvb7.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152732"&gt;@Yoko&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I created a macro with iteration of 3000. The first part looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_0-1638553465078.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66386i17D02755976E6FB0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_0-1638553465078.png" alt="Yoko_0-1638553465078.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The last part looks like this (there are more codes between these):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_2-1638553531920.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66388i267BA6491C94BB81/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_2-1638553531920.png" alt="Yoko_2-1638553531920.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to end the iteration at the end if hosp_2more_timeframe1 = 1, and want to keep going if it's not 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to do this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yoko&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 03 Dec 2021 17:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783977#M25494</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-03T17:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783978#M25495</link>
      <description>&lt;P&gt;Quite similar to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;suggestion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add just after the %macro statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let stop = no;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next, modify this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if hosp_visit_&amp;amp;i &amp;gt;= 2 then hosp_2more_timeframe1=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead, use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if hosp_visit_&amp;amp;i &amp;gt;= 2 then do;
   hosp_2more_timeframe1=1;
   call symputx('stop', 'yes');
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, just before the %END statement, add a statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;stop = yes %then %let i=4000;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 18:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783978#M25495</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-12-03T18:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783986#M25496</link>
      <description>&lt;P&gt;A simple way to exit is to use the %GOTO statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(limit);
%local index;
%do index=1 %to 10;
  %put &amp;amp;=index;
  %if &amp;amp;index &amp;gt;= &amp;amp;limit %then %goto quit;
%end;
%put Limit not reached.;
%quit:
%mend test;
%test(limit=5);
%test(limit=15);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It the condition you want to test is based on data then you can use SAS code to generate a macro variable that the macro code can then test.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to 3000;
...
%let stop=0;
data _null_;
  set ;
  if hosp_2more_timeframe1=1 then call symputx('stop','1');
run;
%if &amp;amp;stop=1 %then %goto quit;
%end;
%quit:
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 18:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783986#M25496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-03T18:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783999#M25497</link>
      <description>&lt;P&gt;I tried your method and it worked (I had to add % to 'then' though.). Thank you. Can I ask you one more thing?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a section above hosp_2more_timeframe1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the program iterate until it finds ed_2more_timeframe1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once ed_2more_timeframe1 is found, it should go to the next section to find hosp_2more_timeframe1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not think the first %if &amp;amp;stop = yes %then %let i = 3000 works.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Yoko_0-1638558947633.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66390i6E1C024737E04048/image-size/large?v=v2&amp;amp;px=999" role="button" title="Yoko_0-1638558947633.png" alt="Yoko_0-1638558947633.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 19:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/783999#M25497</guid>
      <dc:creator>Yoko</dc:creator>
      <dc:date>2021-12-03T19:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional iteration - how can I leave the macro at the end?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/784001#M25498</link>
      <description>&lt;P&gt;Change that first %IF to a %IF /%THEN/%DO/%END block around the part the code you want to execute conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that posting photographs of text is silly. It makes it hard to provide a detailed response.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 19:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Conditional-iteration-how-can-I-leave-the-macro-at-the-end/m-p/784001#M25498</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-03T19:42:07Z</dc:date>
    </item>
  </channel>
</rss>

