<?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 Jump Out of SAS Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828298#M327181</link>
    <description>&lt;P&gt;Is there a way to jump out of a SAS dataset if a condition is met?&amp;nbsp; For example, if I want to include an IF statement at the top of my code to determine if a condition is met, I want to jump over all code to the end of the program so none of the remaining code is executed.&amp;nbsp; I've looked at the GOTO statement but the label where the code jumps to has to be within the same data statement which isn't what I need it to do.&amp;nbsp; Below is a simplified example of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;set two;&lt;/P&gt;&lt;P&gt;If &amp;amp;have_file = 'No' then GOTO endhere;&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;additional code that I want to skip if &amp;amp;have_file = 'No';&lt;/P&gt;&lt;P&gt;******;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;endhere:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2022 15:57:41 GMT</pubDate>
    <dc:creator>zsmith115</dc:creator>
    <dc:date>2022-08-11T15:57:41Z</dc:date>
    <item>
      <title>Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828298#M327181</link>
      <description>&lt;P&gt;Is there a way to jump out of a SAS dataset if a condition is met?&amp;nbsp; For example, if I want to include an IF statement at the top of my code to determine if a condition is met, I want to jump over all code to the end of the program so none of the remaining code is executed.&amp;nbsp; I've looked at the GOTO statement but the label where the code jumps to has to be within the same data statement which isn't what I need it to do.&amp;nbsp; Below is a simplified example of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;set two;&lt;/P&gt;&lt;P&gt;If &amp;amp;have_file = 'No' then GOTO endhere;&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;additional code that I want to skip if &amp;amp;have_file = 'No';&lt;/P&gt;&lt;P&gt;******;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;endhere:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 15:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828298#M327181</guid>
      <dc:creator>zsmith115</dc:creator>
      <dc:date>2022-08-11T15:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828300#M327183</link>
      <description>&lt;P&gt;You definitely can't jump out of a DATA step to a location outside of the DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to look into the macro language, which can be used for conditional execution of SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step, you can conditionally end the data step early.&amp;nbsp; So you could set a macro variable SkipCode=1 and end the data step early.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the macro language you could have your skippable code inside of a %if &amp;amp;skipcode ne 1 %then %do block.&amp;nbsp; Or the macro language has a %GOTO statement which is another option.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 16:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828300#M327183</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-08-11T16:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828302#M327184</link>
      <description>&lt;P&gt;Is the value of &amp;amp;have_file the name of a variable in the data set? If not then the IF is not useful and probably the wrong If. If you are setting the macro variable to avoid executing the data set because of an external to the data set condition then the structure would be MACRO code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if &amp;amp;have_file=NO %then %goto Skipit;
   data one;
       set two;
   end;

%Skipit:&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#800080"&gt;&lt;STRONG&gt;HOWEVER &lt;/STRONG&gt;&lt;FONT color="#000000"&gt;the %goto is only allowed in Macro definition code. Which means defining some of the code involved in a %macro / %mend block, likely with parameters to pass into the macro such as the value of your &amp;amp;have_file macro variable. The calling the compiled macro after the definition. Which depending on everything you are may be doing could be a bit of work. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 16:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828302#M327184</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-11T16:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828303#M327185</link>
      <description>&lt;P&gt;RETURN will end the current iteration of the data step and start the next iteration.&amp;nbsp; If you don't want the implied OUTPUT at the end of the data step to run then use the DELETE statement instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;STOP will end the data step immediately instead of waiting for the normal data step end.&amp;nbsp;Note that most data steps actually end when they read past the end of the inputs in either the SET/MERGE/UPDATE statement or the INPUT statement.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 16:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828303#M327185</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-11T16:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828365#M327223</link>
      <description>&lt;P&gt;If you want to conditionally execute code you need to use MACRO statements.&lt;/P&gt;
&lt;P&gt;You could use the first data step to set a macro variable than you can then use in the macro code.&lt;/P&gt;
&lt;P&gt;For example if the trigger is that there are any observations in TWO where the value of X is larger than 5 you might do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let any_found=0;
data _null_;
  set two;
  where x &amp;gt; 5 ;
  call symputx('any_found','1');
  stop;
run;

%if (&amp;amp;any_found) %then %do;
* other data steps and proc steps;
%end;

* end of program;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Aug 2022 20:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828365#M327223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-11T20:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828371#M327226</link>
      <description>If you there is absolutely no other code after your "endhere", in other words you simply want the whole program to stop, code: if &amp;amp;have_file='No' then abort return; &lt;BR /&gt;&lt;BR /&gt;otherwise use the macro %IF suggestion that others wrote.</description>
      <pubDate>Thu, 11 Aug 2022 21:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828371#M327226</guid>
      <dc:creator>mbuchecker</dc:creator>
      <dc:date>2022-08-11T21:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828379#M327228</link>
      <description>&lt;P&gt;What is the real condition you are testing for? If it whether a certain data file exists or not, pretty much any computer task scheduler can do that within the tool so you don't need to code for it in SAS at all. It does mean that you will have to run your SAS job in batch mode though.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 22:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828379#M327228</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-08-11T22:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828432#M327252</link>
      <description>&lt;P&gt;One way to go if you're using a recent version of SAS9&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %upcase(&amp;amp;have_file) ne NO %then
  %do;

    data one;
      set two;
    run;

    /*******
    additional code that I want to skip if &amp;amp;have_file = 'No';
    ******/

  %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 10:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828432#M327252</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-08-12T10:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Jump Out of SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828440#M327254</link>
      <description>&lt;P&gt;Thanks to everyone that replied with suggestions.&amp;nbsp; I was able to get my code to work using the %if %then %do logic.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 12:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Jump-Out-of-SAS-Dataset/m-p/828440#M327254</guid>
      <dc:creator>zsmith115</dc:creator>
      <dc:date>2022-08-12T12:04:38Z</dc:date>
    </item>
  </channel>
</rss>

