<?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: Error handling in Proc Sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445089#M69401</link>
    <description>&lt;P&gt;Why?&amp;nbsp; You can check the existence of dataset, which is something that maybe necessary.&amp;nbsp; However with such simple code you should not need to check?&amp;nbsp; This:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;%macro sortclass;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds to me like your trying to re-write SAS functionality which is both a waste of time, and less stable.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Mar 2018 09:24:20 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-03-13T09:24:20Z</dc:date>
    <item>
      <title>Error handling in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445046#M69399</link>
      <description>&lt;P&gt;I doing like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;libname DZY 'Path';
Proc sql;
select * from DZ.some_table;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here I have to add an error handling like if something goes wrong in select statement or within the block I have to write error message to an separate text file in the folder. This is what I tried&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%macro sortclass;
 Proc sql;
    select * from DZ.some_table;
    run; 
%if &amp;amp;amp;amp;SQLRC gt 0 %then %goto error;
%error:
proc export data=""
run;

%exit:
%mend; 
%sortclass;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to do an try catch like error handling.., How can do this in effective way. Thanks In advance&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 06:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445046#M69399</guid>
      <dc:creator>Pradeepbanu</dc:creator>
      <dc:date>2018-03-13T06:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445078#M69400</link>
      <description>&lt;P&gt;You should not do this, because you have to re-invent what the sas interpreter already does: checking the syntax of your code.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 08:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445078#M69400</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-03-13T08:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445089#M69401</link>
      <description>&lt;P&gt;Why?&amp;nbsp; You can check the existence of dataset, which is something that maybe necessary.&amp;nbsp; However with such simple code you should not need to check?&amp;nbsp; This:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;%macro sortclass;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds to me like your trying to re-write SAS functionality which is both a waste of time, and less stable.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 09:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445089#M69401</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-13T09:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445186#M69405</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194105"&gt;@Pradeepbanu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I doing like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;libname DZY 'Path';
Proc sql;
select * from DZ.some_table;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here I have to add an error handling like if something goes wrong in select statement or within the block I have to write error message to an separate text file in the folder. This is what I tried&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;%macro sortclass;
 Proc sql;
    select * from DZ.some_table;
    run; 
%if &amp;amp;amp;amp;SQLRC gt 0 %then %goto error;
%error:
proc export data=""
run;

%exit:
%mend; 
%sortclass;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to do an try catch like error handling.., How can do this in effective way. Thanks In advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your proc export is going to throw an error as you are missing ; and you are missing an OUTFILE option.&lt;/P&gt;
&lt;P&gt;Since %exit is not referenced that will generate errors in the log. Also since you do not have anything that skips your&amp;nbsp; proc export it will execute every time. See this code for examples:&lt;/P&gt;
&lt;P&gt;Wrong as it output the value regardless of the value of the test.&lt;/P&gt;
&lt;PRE&gt;%macro dummy(value);
%if &amp;amp;value= 3 %then %goto error;

%error: %Put the value of value is &amp;amp;value;
%mend;

%dummy(3);
%dummy(5);&lt;/PRE&gt;
&lt;P&gt;Marginally better as only has the output when the test is true:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro dummy2(value);
%if &amp;amp;value=3 %then %goto error;
%else %goto exit;
%error: %Put the value of value is &amp;amp;value;
%exit:
%mend;

%dummy2(3);
%dummy2(5);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 21:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445186#M69405</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-13T21:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445326#M69408</link>
      <description>&lt;P&gt;Thanks this is an excellent solution.., I have a question in writing file??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname DZ 'Dataset';&lt;BR /&gt;%macro dummy2(value);&lt;BR /&gt;proc sql;&lt;BR /&gt;select * from DZ.HighV_Trans /* misspelled */&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%if &amp;amp;value=3 %then %goto error;&lt;BR /&gt;%else %goto exit;&lt;BR /&gt;%error:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* here how do I write error in this file??&amp;nbsp; */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc export data = ??&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;outfile ="C/Pradeep/Log.txt"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;/*dbms = csv replace;*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;BR /&gt;%Put the value of value is &amp;amp;value;&lt;BR /&gt;%exit:&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%dummy2(3);&lt;BR /&gt;%dummy2(5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 21:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Error-handling-in-Proc-Sql/m-p/445326#M69408</guid>
      <dc:creator>Pradeepbanu</dc:creator>
      <dc:date>2018-03-13T21:31:28Z</dc:date>
    </item>
  </channel>
</rss>

