<?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: Explicit pass through debug options in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725054#M225157</link>
    <description>Ok, no need of any debug options or statements to debug in case of any&lt;BR /&gt;errors or warnings?&lt;BR /&gt;</description>
    <pubDate>Wed, 10 Mar 2021 04:24:45 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2021-03-10T04:24:45Z</dc:date>
    <item>
      <title>Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724855#M225077</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Can someone help me with the system automatic macro variable and options to see&amp;nbsp;how the execuetion happening with explicit pass through in the code below? This would help us to determine the reason during any error.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*Macro to Integrate data*/
%macro generic_extraction;
Proc sql noprint;
           Connect to SQLSVR (DATAsrc=&amp;amp;DATA. AUTHDOMAIN="&amp;amp;AUTH.");

Create table meta_data as SELECT * 
          FROM  CONNECTION TO SQLSVR 
                ( 
Declare @SQL nvarchar(max) = ''

Select @SQL = @SQL 
&amp;lt;queries&amp;gt;

%if "&amp;amp;function."="LT" %then %do;
where SUBSTRING(dataname, 0, CHARINDEX('_', dataname)) in ('ID','ID')
%end;

%if "&amp;amp;function."="AP" %then %do;
where substring(dataname,1,3)='AP'
%end;

Select @SQL
EXEC(@SQL)
                )
                
          ;   Disconnect from SQLSVR;
Quit;

/*looking for system automatic variable to put the error message in the log*/
%put &amp;amp;sysrc.;

%mend;

/*Macro Execution*/
%generic_extraction; 

&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Mar 2021 16:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724855#M225077</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-09T16:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724915#M225088</link>
      <description>&lt;P&gt;So you are using a SAS macro to dynamically generate some code to run in a remote database that dynamically generates code to run in the remote database?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How big is the code that is being generated in the remote database?&amp;nbsp; Why not just pull down the information needed to generate the code to your local SAS session and generate the code there to submit to the remote database?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 16:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724915#M225088</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-09T16:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724917#M225090</link>
      <description>My code is very small, not more than 20 lines.&lt;BR /&gt;&lt;BR /&gt;I want to execute some SQL Server queries via explicit pass through and I&lt;BR /&gt;want to debug if there is any errors or warnings. Right now without debug&lt;BR /&gt;options it's very difficult find where the issue is.&lt;BR /&gt;&lt;BR /&gt;Also I would like to know if there is any automatic variable which I can&lt;BR /&gt;use in my program to get the return code.&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Mar 2021 17:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724917#M225090</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-09T17:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724921#M225092</link>
      <description>&lt;P&gt;PROC SQL will set some automatic macro variables with error codes. I am not sure how helpful they are in debugging the actual errors.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Check out SQLXRC and SQLXMSG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have much easier time debugging if the SQL you are submitting to run is a simple query and not the dynamic syntax suggested by the snippet in your first example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as
  select * from connection to SQLSRV
(&amp;nbsp;select&amp;nbsp;a,b,c
&amp;nbsp;&amp;nbsp;from&amp;nbsp;myschema.mytable
);
%put&amp;nbsp;&amp;amp;=sqlxrc&amp;nbsp;SQLXMSG=%superq(sqlxmsg);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really need to run something complex in the database then you might need to do that via EXECUTE instead of CONNECTION TO. In which case you will then need to run a separate step to pull the results from where ever the code you execute in the remote database stored them.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 17:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724921#M225092</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-09T17:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724940#M225097</link>
      <description>Thanks. Don't we have any options like symbolgen, mlogic,.. for debugging&lt;BR /&gt;SQL queries with explicit pass through?&lt;BR /&gt;&lt;BR /&gt;How to handle the debugging when working with dynamic syntax via pass through?&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Mar 2021 18:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724940#M225097</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-09T18:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724951#M225102</link>
      <description>&lt;P&gt;You can't have multiple selects and other extraneous SQL Server statements in a SAS SELECT passthru statement. There is no way SAS can make sense of any data coming back from that. If you want to run a whole bunch of SQL Server statements then you have to do that in a SAS EXECUTE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a general rule a&amp;nbsp;SAS SELECT passthru statement must only contain ONE SQL Server query producing one result set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro generic_extraction;
Proc sql noprint;
           Connect to SQLSVR (DATAsrc=&amp;amp;DATA. AUTHDOMAIN="&amp;amp;AUTH.");


  execute ( 
Declare @SQL nvarchar(max) = ''

Select @SQL = @SQL 
&amp;lt;queries&amp;gt;

%if "&amp;amp;function."="LT" %then %do;
where SUBSTRING(dataname, 0, CHARINDEX('_', dataname)) in ('ID','ID')
%end;

%if "&amp;amp;function."="AP" %then %do;
where substring(dataname,1,3)='AP'
%end;

Select @SQL
EXEC(@SQL)
                ) by SQLSVR
 ;   
Disconnect from SQLSVR;
Quit;

/*looking for system automatic variable to put the error message in the log*/
%put &amp;amp;sysrc.;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Mar 2021 19:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/724951#M225102</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-09T19:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725030#M225142</link>
      <description>I got it. Thank you. I see that you have used EXECUTE. How to debug this code?</description>
      <pubDate>Wed, 10 Mar 2021 02:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725030#M225142</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-10T02:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725045#M225152</link>
      <description>&lt;P&gt;Get&amp;nbsp;the SQL Server code working in SQL Server Management Studio first. Once it is working OK there then copy it into your SAS passthru EXECUTE statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 03:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725045#M225152</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-10T03:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725054#M225157</link>
      <description>Ok, no need of any debug options or statements to debug in case of any&lt;BR /&gt;errors or warnings?&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Mar 2021 04:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725054#M225157</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-03-10T04:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Explicit pass through debug options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725057#M225159</link>
      <description>&lt;P&gt;Only the usual passing on of cryptic error messages from other databases which you get by default anyway in a SAS error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find most database error messages aren't particularly helpful and it is better just to start with a really simple query that works, then add more statements one by one testing each change.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 05:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explicit-pass-through-debug-options/m-p/725057#M225159</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-10T05:40:32Z</dc:date>
    </item>
  </channel>
</rss>

