<?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: Skip few iterations when condition met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436265#M108501</link>
    <description>And option nomprint</description>
    <pubDate>Mon, 12 Feb 2018 16:10:36 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-02-12T16:10:36Z</dc:date>
    <item>
      <title>Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436226#M108490</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I run 2 do-loop (DO a and DO h). In the inner loop, when the record of the output file is equal to a number, say 0, I want to skip&amp;nbsp;2&amp;nbsp;h (2 steps in inner loop).&lt;/P&gt;
&lt;P&gt;In this example,&amp;nbsp;for age=12 and Height=50, there is 0 record, so the next iteration will be age=12 and height = 57&amp;nbsp;(new h = 1+2).&lt;/P&gt;
&lt;P&gt;I guess it will be something like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		%if &amp;amp;N_record=0 %then goto "THIS PLACE";

	%end;
		"THIS PLACE" &amp;amp;h=&amp;amp;h+2;
	%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you so much for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; set sashelp.class; run;

%Macro skip;
	%let age_list	 = 12 13 ;
	%let Height_list = 50 55 56 57 58;

	%do a=1 	%to %sysfunc(countw(&amp;amp;age_list));
	%do H=1 	%to %sysfunc(countw(&amp;amp;Height_list));

		data Age&amp;amp;a._Height&amp;amp;H ; set have;
		if age=(value of age associated with &amp;amp;a) and height&amp;gt;(value of Height associated with &amp;amp;h);run;

		proc sql noprint; select count(*) into:N_record from Age&amp;amp;a._Height&amp;amp;H;quit;

		%if &amp;amp;N_record=0 %then new h =&amp;amp;h+2;

	%end;
	%end;
%Mend;

%SKIP;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;KEY&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have; set sashelp.class; run;

options mlogic symbolgen ;

%Macro skip;
	%let age_list	 = 12 13 ;
	%let Height_list = 50 55 56 57 58;

	%do a=1 	%to %sysfunc(countw(&amp;amp;age_list));
	%do H=1 	%to %sysfunc(countw(&amp;amp;Height_list));

		%put &amp;amp;h;
		data Age&amp;amp;a._Height&amp;amp;H ; set have;
		if age=%scan(&amp;amp;age_list, &amp;amp;a) and height&amp;lt;%scan(&amp;amp;height_list, &amp;amp;h);run;

		proc sql noprint; select count(*) into:N_record from Age&amp;amp;a._Height&amp;amp;H;quit;

		%if &amp;amp;n_record = 0 %then %let h = %eval(&amp;amp;h + 2) ; /*This new h will go to the next step at the %end to make it h+1--&amp;gt; +2 become +2+1= +3;  */

	%end;
	%end;
%Mend;

%SKIP;

options nosymbolgen nomlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436226#M108490</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-12T16:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436238#M108492</link>
      <description>&lt;P&gt;You're present statement is very close.&amp;nbsp; It can stay in the same location, but switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;n_record=0 %then %let h = &amp;amp;h + 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You still have a gap in the logic ... how do you retrieve "value of age associated with &amp;amp;a" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%scan(&amp;amp;age_list, &amp;amp;a)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly for the height list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%scan(&amp;amp;height_list, &amp;amp;h)&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 14:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436238#M108492</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-12T14:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436242#M108493</link>
      <description>&lt;P&gt;What is it your trying to do?&amp;nbsp; It seems like every post you have made here seems to be trying to re-create base SAS in macro language.&amp;nbsp; Why not simplfy your life and use Base SAS, why continue to fight the system?&amp;nbsp; from the code below, you simply want to create a set of counts based on a categorisation.&amp;nbsp; Categorise your data in one datastep, e.g.&lt;/P&gt;
&lt;PRE&gt;data inter;
  set have;
  if age=12 and 50 &amp;lt;= height &amp;lt; 58 then cat="Cat1";
  ...;
run;

proc means data=inter;
  var cat1;
  output out=want;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Macro is not a replacement for base SAS!!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 15:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436242#M108493</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-12T15:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436250#M108496</link>
      <description>&lt;P&gt;Since I have big marco, so I try to optimize the process using this method.&lt;/P&gt;
&lt;P&gt;By the way, I use your code, SAS run the first iteration and error notice show up, I guess when it check the %IF condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; set sashelp.class; run;

%Macro skip;
	%let age_list	 = 12 13 ;
	%let Height_list = 50 55 56 57 58;

	%do a=1 	%to %sysfunc(countw(&amp;amp;age_list));
	%do H=1 	%to %sysfunc(countw(&amp;amp;Height_list));

		%put &amp;amp;h;

		data Age&amp;amp;a._Height&amp;amp;H ; set have;
		if age=%scan(&amp;amp;age_list, &amp;amp;a) and height&amp;lt;%scan(&amp;amp;height_list, &amp;amp;h);run;

		proc sql noprint; select count(*) into:N_record from Age&amp;amp;a._Height&amp;amp;H;quit;

		%if &amp;amp;N_record=0 %then %let h =&amp;amp;h+2;

	%end;
	%end;
%Mend;

%SKIP;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;18487228 %Mend;&lt;BR /&gt;18487229&lt;BR /&gt;18487230 %SKIP;&lt;BR /&gt;1&lt;/P&gt;
&lt;P&gt;NOTE: There were 19 observations read from the data set WORK.HAVE.&lt;BR /&gt;NOTE: The data set WORK.AGE1_HEIGHT1 has 0 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt; real time 0.00 seconds&lt;BR /&gt; cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt; real time 0.00 seconds&lt;BR /&gt; cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR: The index variable in the %DO H loop has taken on an invalid or missing value. The&lt;BR /&gt; macro will stop executing.&lt;BR /&gt;ERROR: The macro SKIP will stop executing.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 15:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436250#M108496</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-12T15:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436255#M108498</link>
      <description>&lt;P&gt;Hmmmm ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code looks OK.&amp;nbsp; Here's what I would try.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace the line that skips:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;n_record = 0 %then %let h = %eval(&amp;amp;h + 2) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And before running, add this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mlogic symbolgen;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will force the macro processor to tell us what it is looking at, as it interprets the program.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 15:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436255#M108498</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-12T15:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436260#M108499</link>
      <description>&lt;P&gt;SAS now runs but it skip from 1 to 4 instead of 1 to 3.&lt;/P&gt;
&lt;P&gt;Also an error on the option show up.&lt;/P&gt;
&lt;P&gt;By the way, how to turn this option off so Log file come back to normal?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;18487399 options mlogic symbolgen noprint;&lt;BR /&gt;11: LINE and COLUMN cannot be determined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable H resolves to 1&lt;BR /&gt;1&lt;BR /&gt;SYMBOLGEN: Macro variable A resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable H resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable AGE_LIST resolves to 12 13&lt;BR /&gt;SYMBOLGEN: Macro variable A resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable HEIGHT_LIST resolves to 50 55 56 57 58&lt;BR /&gt;SYMBOLGEN: &lt;FONT color="#FF0000"&gt;Macro variable H resolves to 1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable N_RECORD resolves to 0&lt;BR /&gt;MLOGIC(SKIP): %IF condition &amp;amp;n_record = 0 is TRUE&lt;BR /&gt;MLOGIC(SKIP): %LET (variable name is H)&lt;BR /&gt;SYMBOLGEN: Macro variable H resolves to 1&lt;BR /&gt;MLOGIC(SKIP): %DO loop index variable H is now 4; loop will iterate again.&lt;BR /&gt;MLOGIC(SKIP): %PUT &amp;amp;h&lt;BR /&gt;SYMBOLGEN: &lt;FONT color="#FF0000"&gt;Macro variable H resolves to 4&lt;/FONT&gt;&lt;BR /&gt;4&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436260#M108499</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-12T16:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436263#M108500</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;H should only be increased by 1 since a new increment is added by the loop.&lt;/P&gt;
&lt;P&gt;Try %let h=%eval(&amp;amp;h.+1);&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436263#M108500</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-02-12T16:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436265#M108501</link>
      <description>And option nomprint</description>
      <pubDate>Mon, 12 Feb 2018 16:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436265#M108501</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-02-12T16:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436266#M108502</link>
      <description>&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, where should I post that kind of Macro question or I can post here in the "Base SAS Programming".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436266#M108502</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-12T16:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436267#M108503</link>
      <description>&lt;P&gt;Yes, skipped from 1 to 4 because you asked for that in describing the problem ... skip from 50 to 57.&amp;nbsp; As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;recommended, switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... %let h&amp;nbsp;= %eval(&amp;amp;h + 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you can remove the options statement since the error is gone.&amp;nbsp; If you are using a continuous session (such as Enterprise Guide), you can re-set them with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options nosymbolgen nomlogic;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436267#M108503</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-12T16:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436268#M108504</link>
      <description>&lt;P&gt;You are right. Now I understand the process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, where should I post that kind of Macro question or I can post here in the "Base SAS Programming".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436268#M108504</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-02-12T16:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Skip few iterations when condition met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436269#M108505</link>
      <description>&lt;P&gt;You posted in the right place (which is Base SAS Programming).&amp;nbsp; There is also a General SAS Programming category, but the description of Base SAS Programming specifically includes macro language.&amp;nbsp; Sometimes it's difficult to tell where to post because a problem might span more than one category.&amp;nbsp; The most important advice is to post just once, not twice.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 16:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-few-iterations-when-condition-met/m-p/436269#M108505</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-12T16:25:03Z</dc:date>
    </item>
  </channel>
</rss>

