<?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 How to break out of %NRSTR to execute a %GOTO statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440543#M110060</link>
    <description>&lt;P&gt;Here's my code:&lt;/P&gt;&lt;PRE&gt;%sysfunc(ifc(%sysfunc(libref(LIBNAME))
		,%nrstr(%put ERROR: LIBNAME Libref does not exist.; %goto exit;)
		,%nrstr(%put NOTE: LIBNAME Libref exists.;)	));&lt;/PRE&gt;&lt;P&gt;My issue is of course that the %NRSTR is causing an issue with the %goto statement:&lt;/P&gt;&lt;PRE&gt;ERROR: The %GOTO statement is not valid in open code.&lt;/PRE&gt;&lt;P&gt;%NRSTR&amp;nbsp;&lt;STRONG&gt;must&lt;/STRONG&gt; exist to allow the 'ifc' to properly run the true/false statements. Without %NRSTR, ifc executes all of the statements regardless of the outcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%unquote, %bquote %nrbquote %str etc etc have all been used to varying degrees of failure. Any idea how I break that portion of the code out of the %NRSTR to allow the %GOTO to work?&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2018 16:05:45 GMT</pubDate>
    <dc:creator>_Dan_</dc:creator>
    <dc:date>2018-02-27T16:05:45Z</dc:date>
    <item>
      <title>How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440543#M110060</link>
      <description>&lt;P&gt;Here's my code:&lt;/P&gt;&lt;PRE&gt;%sysfunc(ifc(%sysfunc(libref(LIBNAME))
		,%nrstr(%put ERROR: LIBNAME Libref does not exist.; %goto exit;)
		,%nrstr(%put NOTE: LIBNAME Libref exists.;)	));&lt;/PRE&gt;&lt;P&gt;My issue is of course that the %NRSTR is causing an issue with the %goto statement:&lt;/P&gt;&lt;PRE&gt;ERROR: The %GOTO statement is not valid in open code.&lt;/PRE&gt;&lt;P&gt;%NRSTR&amp;nbsp;&lt;STRONG&gt;must&lt;/STRONG&gt; exist to allow the 'ifc' to properly run the true/false statements. Without %NRSTR, ifc executes all of the statements regardless of the outcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%unquote, %bquote %nrbquote %str etc etc have all been used to varying degrees of failure. Any idea how I break that portion of the code out of the %NRSTR to allow the %GOTO to work?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440543#M110060</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2018-02-27T16:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440551#M110065</link>
      <description>&lt;P&gt;No, I think your problem is in understanding the difference between Base SAS code and Macro code.&amp;nbsp; &amp;nbsp;The log is telling you that you can't do macro code in datastep.&amp;nbsp; What you likely want is:&lt;/P&gt;
&lt;PRE&gt;%if %sysfunc(libref(LIBRARY)) %then %do;
  %put NOTE: LIBNAME Libref exists;
%end;
%else %do;
  %put ERROR: LIBNAME does not exist;
%end;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440551#M110065</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-27T16:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440553#M110066</link>
      <description>This entire process runs within a %macro, my understanding is fine. %NRSTR is affecting the compilation of the %goto.</description>
      <pubDate>Tue, 27 Feb 2018 16:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440553#M110066</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2018-02-27T16:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440560#M110069</link>
      <description>&lt;P&gt;I can't promise how this will work in the context of your macro, but the usual way to mask the effect of % within %NRSTR is to refer to the % as %%:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;,%nrstr(%%put ERROR: LIBNAME Libref does not exist.; %%goto exit; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is the possibility of needing to %unquote, but first try it without %unquote to see if that will work.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440560#M110069</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-27T16:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440562#M110071</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically everything works apart from the %goto. I've had various methods of running this little checker, usually the end result would be a %let statement instead of this %goto. That works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, the only problem is the %goto. There's no need for double %% because I'm not trying to escape anything (that's not what NRSTR is doing here). In fact, I &lt;EM&gt;want&lt;/EM&gt; the %GOTO to work, and in theory it does, but SAS is seeing it outside of the context of it being inside of a %macro. I could literally write this statement anywhere else right now and it would work, just not inside of the %NRSTR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also tried UNQUOTE around the %goto bit but EGuide acts very strange - clearly it's causing a mismatch of some sorts and EGuide has no idea how to compile and run the entire macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440562#M110071</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2018-02-27T16:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440573#M110077</link>
      <description>&lt;P&gt;Question seems silly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For %GOTO to work you need to be in a macro. If you are in a macro then why the heck are you using data step function IFC instead of just use %IF?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to see if you can build a computed %GOTO?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440573#M110077</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-27T16:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440580#M110082</link>
      <description>&lt;P&gt;Unfortunately, next suggestion would be to follow the &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;advice and get rid of IFC.&amp;nbsp; There should be no problem using %goto in this context:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%else %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; %put ERROR: LIBNAME does not exist;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; %goto exit;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440580#M110082</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-27T16:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440781#M110193</link>
      <description>&lt;P&gt;Approach is 50% programmatic and 50% cosmetic. I've replaced it with a %let error = 1 and then I query this later. There's more than one of these statements so I just let them all run and now I query the outcome afterwards. %goto is now called by its own %if error = 1 %then...&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 07:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440781#M110193</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2018-02-28T07:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440793#M110198</link>
      <description>&lt;P&gt;The %goto statement can only be used inside a macro. However, even inside a macro you will get the same message when trying to use %goto like that (because the statement has not been compiled as part of the macro). If you are inside a macro, there is ho need to make things so complicated, though, just use:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(libref(libname)) %then %do;
  %put ERROR: LIBNAME Libref does not exist.; &lt;BR /&gt;  %goto exit;&lt;BR /&gt;  %end;&lt;BR /&gt;%else&lt;BR /&gt;  %put NOTE: LIBNAME Libref exists.; &lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Except that unless you have some cleanup code that you want to execute at the %exit label, you could just use %return to stop macro execution.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 08:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440793#M110198</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-02-28T08:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to break out of %NRSTR to execute a %GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440795#M110199</link>
      <description>&lt;P&gt;Thanks for that, I'd been using %if %then %do for a long time but wanted to use IFC more after seeing (and using) some very good examples. Looks like that's just not possible when calling another macro function but everything else works without issue. Shame, it's the only time I ever needed to use %goto as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 08:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-out-of-NRSTR-to-execute-a-GOTO-statement/m-p/440795#M110199</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2018-02-28T08:41:22Z</dc:date>
    </item>
  </channel>
</rss>

