<?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 difference between Statment GOTO and %GOTO in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238117#M43720</link>
    <description>&lt;P&gt;I was running the following code given in the sas documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data info;   
   input x;
   if 1&amp;lt;=x&amp;lt;=5 then go to add;
   put x=;
   add: sumx+x;
   datalines;
7
6
323
;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;I think " if condition is false", why it is executing the statment in the add label.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas in the context of the %goto, it executes %goto label when it is true only (code below- &lt;A href="http://www.lexjansen.com/nesug/nesug03/cc/cc016.pdf)." target="_blank"&gt;http://www.lexjansen.com/nesug/nesug03/cc/cc016.pdf).&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO READ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%DO I = 1 %TO 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%IF &amp;amp;I = 3 %THEN %GOTO OUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;DATA CTY_&amp;amp;I;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;INFILE "D:\NESUG\CTY_&amp;amp;I";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;INPUT ID F96 F97 F98;&lt;/P&gt;&lt;P&gt;&amp;nbsp; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %OUT: %END;&lt;/P&gt;&lt;P&gt;%MEND READ;&lt;/P&gt;&lt;P&gt;%READ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am really confused now. &amp;nbsp;I thought %goto was just macro counterpart &amp;nbsp;of goto.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2015 17:52:46 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2015-12-07T17:52:46Z</dc:date>
    <item>
      <title>difference between Statment GOTO and %GOTO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238117#M43720</link>
      <description>&lt;P&gt;I was running the following code given in the sas documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data info;   
   input x;
   if 1&amp;lt;=x&amp;lt;=5 then go to add;
   put x=;
   add: sumx+x;
   datalines;
7
6
323
;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;I think " if condition is false", why it is executing the statment in the add label.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas in the context of the %goto, it executes %goto label when it is true only (code below- &lt;A href="http://www.lexjansen.com/nesug/nesug03/cc/cc016.pdf)." target="_blank"&gt;http://www.lexjansen.com/nesug/nesug03/cc/cc016.pdf).&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO READ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%DO I = 1 %TO 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%IF &amp;amp;I = 3 %THEN %GOTO OUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;DATA CTY_&amp;amp;I;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;INFILE "D:\NESUG\CTY_&amp;amp;I";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;INPUT ID F96 F97 F98;&lt;/P&gt;&lt;P&gt;&amp;nbsp; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %OUT: %END;&lt;/P&gt;&lt;P&gt;%MEND READ;&lt;/P&gt;&lt;P&gt;%READ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am really confused now. &amp;nbsp;I thought %goto was just macro counterpart &amp;nbsp;of goto.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 17:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238117#M43720</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-07T17:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: difference between Statment GOTO and %GOTO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238124#M43722</link>
      <description>&lt;P&gt;Your data step example ADD is just a label. Since you do not have any way of not executing it then you get the result everytime. The code below is the same as yours.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data info;   
   input x;
   if 1&amp;lt;=x&amp;lt;=5 then go to add;
   put x=;
   add: 
   sumx+x;
   datalines;
7
6
323
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do not want the sumx+x executed for every step the Return is used with Goto&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data info;
   input x;
   if 1&amp;lt;=x&amp;lt;=5 then go to add;
   put x=;
   return;    
      /* SUM statement not executed */
      /* if x&amp;lt;1 or x&amp;gt;5              */
   add: sumx+x;
   datalines;
7
6
323
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 20:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238124#M43722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-07T20:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: difference between Statment GOTO and %GOTO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238242#M43753</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BallardW is correct in the data step code posted and his explanation of the 'return;' statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To explain why %GOTO behaved as it did, consider what is after the %IF in your code: it is a complete datastep with a RUN; which terminates that group of SAS statements. In that respect it is similar to "return;" (not strictly true, but close enough). Remember also that macro language is simply a mechanism for generating SAS code - it has its own execution logic that passes the generated code for SAS to compile and execute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the effect of your macro conditional is to either generate a whole data step (when the condition is false), or to skip that by jumping to the %END statement, labelled with the name OUT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, on a coding style point, I recommend *always* having an explicit "else..." along with "if...then..." - too often I've had to debug someone else's code that has misbehaved because the author didn't do that!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Steve M.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 12:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-Statment-GOTO-and-GOTO/m-p/238242#M43753</guid>
      <dc:creator>SteveM_UK</dc:creator>
      <dc:date>2015-12-08T12:00:25Z</dc:date>
    </item>
  </channel>
</rss>

