<?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: Recove from error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523626#M142273</link>
    <description>Obvious error is %do i = 1 % %to 100;&lt;BR /&gt;&lt;BR /&gt;Should be %do i = 1 %to 100;</description>
    <pubDate>Thu, 27 Dec 2018 13:01:32 GMT</pubDate>
    <dc:creator>tomrvincent</dc:creator>
    <dc:date>2018-12-27T13:01:32Z</dc:date>
    <item>
      <title>Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523623#M142272</link>
      <description>&lt;P&gt;I have a sas code where I have a list of something, and I cycle some code in a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Run_All;

%do i=1 %to 100;
  %Run_Single(&amp;amp;i);
%end;

%mend;

%Run_All;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inside each Run_Single at some point an error may occour (for instance there are duplicate id for proc transpose, or a dataset in "set" statement does not exists, or a dataset used to set some macrovars is emply so the macrovars are undefined, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If such error occurs, that is ok INSIDE the single cycle. But when the next cycle begins it must be free of all previous errors, i.e. the cycles must be independent!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I achieve that? If in the i-th cycle happens something, in the i+1-th cycle I get&amp;nbsp;"was not replaced because this step was stopped." so sas refuses to keep processing the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tryed setting "%let syscc=0",&amp;nbsp;"options obs=max replace;" at the beginning of each cycle but it still breaks from i+1-th on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 13:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523623#M142272</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2018-12-27T13:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523626#M142273</link>
      <description>Obvious error is %do i = 1 % %to 100;&lt;BR /&gt;&lt;BR /&gt;Should be %do i = 1 %to 100;</description>
      <pubDate>Thu, 27 Dec 2018 13:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523626#M142273</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-12-27T13:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523627#M142274</link>
      <description>That was a typo, fixed thank you.&lt;BR /&gt;&lt;BR /&gt;The error I am talking about is INSIDE each call of Run_Single.</description>
      <pubDate>Thu, 27 Dec 2018 13:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523627#M142274</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2018-12-27T13:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523708#M142313</link>
      <description>Any reason you can't fix those errors within run_single?</description>
      <pubDate>Thu, 27 Dec 2018 20:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523708#M142313</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-12-27T20:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523709#M142314</link>
      <description>Unfortunately not, because the data source is external, I have no control of it, and there are many many reasons because something may go wrong. I may of course check for duplicates in all tables, check for primary keys, check for existence etc, but the code would become a mess! So it is a lot better to just let the code go wrong and continue to next iteration. But, to to that sas needs to recover to errors like it was just started.&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Dec 2018 21:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523709#M142314</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2018-12-27T21:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523863#M142387</link>
      <description>&lt;P&gt;How are you running your program? If you are running in batch mode SAS will have the SYNTAXCHECK option switched on by default. That means OBS = 0 will be set as soon as SAS hits an error and no further processing of data will occur. You may get closer to what you want by using: options NOSYNTAXCHECK;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Dec 2018 05:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523863#M142387</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-12-30T05:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523925#M142419</link>
      <description>I'd suggest do a google search for 'sas continue after error' and see if any of those solutions work for you.</description>
      <pubDate>Mon, 31 Dec 2018 13:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523925#M142419</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-12-31T13:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523968#M142433</link>
      <description>&lt;P&gt;The appropriate solution is to determine such thing as why a data set is empty prior to using it or have code using the set test before use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be able to work with this %macro if you can determine why or what is persisting between cycles. You should be able to reset the macro symbol table between YOUR calls to this macro and possibly clean up afterwards. Conceptually:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro Run_All;

%do i=1 %to 100;
  %MyCleanBeforeMacro
  %Run_Single(&amp;amp;i);
   %MyCleanAfterMacro
%end;

%mend;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But we don't have enough information about what may be getting set, read or stored by a not-very-well designed program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example of duplicate ID in proc transpose is data set&amp;nbsp;related. So what kind of persistence is there that would cause that again? If the same data sets are used you can't expect a "clean" run if the bad data is still there.&lt;/P&gt;
&lt;P&gt;Things like a data set existing are pretty easy to test for so beat up who ever is supplying %Run_single to fix that at least. Here's an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
   if exist("work.mydata") then call symputx('itexists',1);
   else call symputx('itexists',0);
run;

%if &amp;amp;itexists = 1 %then %do;
&amp;lt;whatever is required when the set work.mydata exists&amp;gt;
%end;
%else %do;
&amp;lt;whatever makes sense when work.mydata does not exist&amp;gt;
%end;&lt;/PRE&gt;
&lt;P&gt;OR you test for the data&amp;nbsp;set in the "clean before" and possibly don't even bother to call the %Run_single since it would "fail".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on how you are setting the macro variables from a data set you have different options. If using a data set then the code above is easy to modify when one or more variables that are required are not available (or missing) in the data set. If using Proc SQL with an :into the automatic macro variable &amp;amp;sqlobs is likely&amp;nbsp;set with the number of elements in the list. If 0 then you have flag to set other variables or skip processing steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to say that I am not impressed with what appears to be production code with so many beginner errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may have to run your code with OPTIONS MPRINT SYMBOLGEN and/or MLOGIC and possibly send you log to a text file as the log&amp;nbsp;can get very large to find what is actually breaking.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 23:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/523968#M142433</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-31T23:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525660#M143044</link>
      <description>"no syntaxcheck" was exactly what I was looking for thank you, now the i+1-th iteration runs correctly even though the i-th got some error.&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Jan 2019 08:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525660#M143044</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2019-01-09T08:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525661#M143045</link>
      <description>&lt;P&gt;Yes you are right, if I am aware of what can be wrong I use to insert some "checkpoints" in the code to check if a table exists, if a table is empty, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there are some cases (like this one) in which if you use external sources, external databases, external files (excel, etc), there are so many things that may go wrong that&amp;nbsp;it would be very very very verbose to predict all possibilities (connection failed, schema does not exists, table does not exists, column does not exists, column type is wrong,&amp;nbsp;a table is not well indexed on a databases so the query has a timeout, an excel has a wrong number of columns, an excel sheet name is wrong, etc etc sooo many).&lt;/P&gt;
&lt;P&gt;So in these case I prefer to just run the code and check at the end if something went wrong: if so, I notify the users responsible of the sources and I proceed to the next iteration. If they want their output, they must fix their sources and then the procedure can run again, that's perfectly fine! I don't care and I move on to the next iteration which is completely independent of the results of the previous one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 08:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525661#M143045</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2019-01-09T08:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Recove from error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525832#M143095</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5590"&gt;@Edoedoedo&lt;/a&gt; - I like your approach. I agree it is impossible to cater for everything that might go wrong with an application. NOSYNTAXCHECK is a great option for ensuring SAS continues processing if there is a problem. For non-iterating batch jobs I prefer SYNTAXCHECK as it causes the job to complete very quickly and makes it very obvious there has been an error.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 19:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recove-from-error/m-p/525832#M143095</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-01-09T19:35:02Z</dc:date>
    </item>
  </channel>
</rss>

