<?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: Catch unexpected quotes in external code and recover program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402430#M97712</link>
    <description>&lt;P&gt;My previous post should show you that there is no remedy. An option is to copy the "magic code" that Enterprise Guide sends after every code submitted, but for every idiot-proof solution devised, a new, improved idiot arises to overcome it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best solution is to not have code in macro variables (or simply entered as input); instead have parameters set, which you can test for validity, which then&amp;nbsp;&lt;EM&gt;influence&lt;/EM&gt; code already written.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2017 17:17:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-09T17:17:03Z</dc:date>
    <item>
      <title>Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402393#M97695</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am stuck in a problem with unbalanced quotes and would greatly appreciate your help. I have a macro as shown below. Here I have an external piece of custom code pasted in via a macro variable (or %include statement). This custom code isn't tested upfront until it is used here. Sometimes this custom code has unbalanced quotes and causes my remaining code to fail. I have tried the strings such as&amp;nbsp;*’; *”; */; or&amp;nbsp;*); */; /*’*/ /*”*/; %mend; after the custom code, to catch such issues and continue with my remaining code normally. But nothing so far has been successful. Please help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Vineet&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro mymacro;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-- my code --;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;custom_code; * This macro variable inserts custom code and sometimes have unbalanced&amp;nbsp;quotes ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-- my remaining code --;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend mymacro;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mymacro;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 15:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402393#M97695</guid>
      <dc:creator>vineet7878_gmail_com</dc:creator>
      <dc:date>2017-10-09T15:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402428#M97710</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163853"&gt;@vineet7878&lt;/a&gt;_gmail_com wrote:&lt;BR /&gt;
&lt;P&gt;This custom code isn't tested upfront until it is used here.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Shoot the one who gives you untested code. With a field howitzer. 3 hours.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 17:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402428#M97710</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-09T17:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402429#M97711</link>
      <description>&lt;P&gt;I suggest&amp;nbsp;you insert a sanity check for basic syntax before starting the computation. You can use a DATA step to read the custom&amp;nbsp;code as a series of strings and perform basic syntax checking such as counting the number&amp;nbsp;of opening/closing parentheses. You can abort the computation if the &amp;amp;custom_code is invalid:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, suppose you take the custom string and write it to a temporary file.&amp;nbsp; The following example assumes that you write it to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C:/temp/temp.sas&lt;/P&gt;
&lt;P&gt;and that the file contains the following text:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (f&amp;gt;0) and (f&amp;lt;1 then do;&lt;BR /&gt; s = "is this string closed?";&lt;BR /&gt; t = "My name is;&lt;BR /&gt; x = log(t;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can parse that text file, as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* check open/close parentheses and balanced quotes */
data _null_;
infile 'C:/temp/temp.sas' end=eof;
input;
netParen + countc(_infile_, '(') 
         - countc(_infile_, ')');
sumQuotes + countc(_infile_, '"');
if eof then do;
	balancedQuotes = mod(sumQuotes+1, 2);
   put netParen=;        /* if 0 then parens balanced */
   put balancedQuotes=;  /* if 0, then quotes vbalanced */
end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 17:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402429#M97711</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-09T17:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402430#M97712</link>
      <description>&lt;P&gt;My previous post should show you that there is no remedy. An option is to copy the "magic code" that Enterprise Guide sends after every code submitted, but for every idiot-proof solution devised, a new, improved idiot arises to overcome it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best solution is to not have code in macro variables (or simply entered as input); instead have parameters set, which you can test for validity, which then&amp;nbsp;&lt;EM&gt;influence&lt;/EM&gt; code already written.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 17:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402430#M97712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-09T17:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402434#M97715</link>
      <description>&lt;P&gt;I like Ricks solution. The custom code is coming from SAS code entered as snippets within excel based data specifications file, from where it is exported to SAS to run.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess, I need to build code testing module to test such code, before actually running it. I was hoping to not do such checking and just have some magic string at the end of code to catch the issues and continue without disruption.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 17:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402434#M97715</guid>
      <dc:creator>vineet7878_gmail_com</dc:creator>
      <dc:date>2017-10-09T17:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Catch unexpected quotes in external code and recover program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402596#M97787</link>
      <description>&lt;P&gt;It is probably best to run each block of the untested code in its own SAS environment.&amp;nbsp; That way when it fails it does not fail the master job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps for each snippet of code generate a stand alone program that tests it and run it as a separate SAS job. Then scan the log for a success code before attempting to use the code.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 04:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catch-unexpected-quotes-in-external-code-and-recover-program/m-p/402596#M97787</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-10T04:32:36Z</dc:date>
    </item>
  </channel>
</rss>

