<?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 Can I %include code within PROC SQL explicit pass-through? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-include-code-within-PROC-SQL-explicit-pass-through/m-p/410729#M100366</link>
    <description>&lt;P&gt;I've written a code generation data step which generates code to create a view in SQL Server.&amp;nbsp; It uses metadata stored in Excel for column names, types, etc.&amp;nbsp; The view contains hundreds of columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I won't bother posting the view generation code; suffice it to say in creates syntactically correct code for SQL Server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to execute the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;

*** data _null_ step to generate code within the code temporary file ;

proc sql noprint;
   connect using pdcdev;
   execute (
      %include code
   ) by pdcdev;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODBC_603: Executed: on connection 9
%include code
 
ERROR: CLI execute error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '%'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought the macro processor resolved all macro references within explicit pass-through...&lt;STRONG&gt;including %include&lt;/STRONG&gt;???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The workaround is easy enough, just move the explicit pass-through code to within the code generation step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm wanting to get a better understanding of the interaction of explicit pass-through and %include.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks...&lt;/P&gt;</description>
    <pubDate>Sun, 05 Nov 2017 23:56:43 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2017-11-05T23:56:43Z</dc:date>
    <item>
      <title>Can I %include code within PROC SQL explicit pass-through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-include-code-within-PROC-SQL-explicit-pass-through/m-p/410729#M100366</link>
      <description>&lt;P&gt;I've written a code generation data step which generates code to create a view in SQL Server.&amp;nbsp; It uses metadata stored in Excel for column names, types, etc.&amp;nbsp; The view contains hundreds of columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I won't bother posting the view generation code; suffice it to say in creates syntactically correct code for SQL Server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to execute the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;

*** data _null_ step to generate code within the code temporary file ;

proc sql noprint;
   connect using pdcdev;
   execute (
      %include code
   ) by pdcdev;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODBC_603: Executed: on connection 9
%include code
 
ERROR: CLI execute error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '%'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought the macro processor resolved all macro references within explicit pass-through...&lt;STRONG&gt;including %include&lt;/STRONG&gt;???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The workaround is easy enough, just move the explicit pass-through code to within the code generation step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm wanting to get a better understanding of the interaction of explicit pass-through and %include.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks...&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 23:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-include-code-within-PROC-SQL-explicit-pass-through/m-p/410729#M100366</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2017-11-05T23:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can I %include code within PROC SQL explicit pass-through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-include-code-within-PROC-SQL-explicit-pass-through/m-p/410733#M100367</link>
      <description>&lt;P&gt;No.&amp;nbsp; The %INCLUDE needs to be at a statement boundary and for SQL passthru the SAS statement that is being compiled/run is the SELECT or EXECUTE statement, not the SQL statement&amp;nbsp; that is being sent as passthru code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you could put the BEGINNING of the SAS SQL statement in another file and include them both.&amp;nbsp; You could also put the ending in a third file, but that is not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is trivial example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename part1 temp;
filename part2 temp;
data _null_;
 file part1 ;
 put 'select * from connection to td (';
 file part2 ;
 put 'select 5 as x' ;
 stop;
run;
proc sql ;
%tdconnect;
%include part1 part2  / source2 ;
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which retrieves the one record query result and has SAS log that looks like this.&lt;/P&gt;
&lt;PRE&gt;120   %include part1 part2  / source2 ;
NOTE: %INCLUDE (level 1) file PART1 is file
      /scratch/SAS_workE856002B6767/#LN00041.
121  +select * from connection to td (
NOTE: %INCLUDE (level 1) ending.
NOTE: %INCLUDE (level 1) file PART2 is file
      /scratch/SAS_workE856002B6767/#LN00042.
122  +select 5 as x
NOTE: %INCLUDE (level 1) ending.
123   );

TERADATA_0: Prepared: on connection 0
select 5 as x


TERADATA_1: Executed: on connection 0
select 5 as x

TERADATA: trget - rows to fetch: 1

Summary Statistics for TERADATA are:
Total row fetch seconds were:                       0.000003
Total SQL execution seconds were:                   0.002740
Total SQL prepare seconds were:                     0.002438
Total seconds used by the TERADATA ACCESS engine were     0.088820&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 14:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-include-code-within-PROC-SQL-explicit-pass-through/m-p/410733#M100367</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-06T14:26:55Z</dc:date>
    </item>
  </channel>
</rss>

