<?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: %include inside Oracle Connection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812496#M320586</link>
    <description>&lt;P&gt;That works as well.&lt;/P&gt;
&lt;P&gt;Note you just need to have the beginning of the SAS statement in the PRE file because the %INCLUDE statement cannot be called in the middle of a SAS statement. There is no need for a POST file, you can just have that part of the statement in the program itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example you can try.&amp;nbsp; The is example is just using SASHELP dataset to demonstrate the idea.&amp;nbsp; Just update the prefix code to reference Oracle if you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=code;
filename code temp;

parmcards;
select * from sashelp.class
;

options parmcards=pre;
filename pre temp;

parmcards;
create table xx as (
;

proc sql;
%include pre code / source2;
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;347  proc sql;
348  %include pre code / source2;
NOTE: %INCLUDE (level 1) file PRE is file
      C:\Users\...\#LN00096.
349 +create table xx as (
NOTE: %INCLUDE (level 1) ending.
NOTE: %INCLUDE (level 1) file CODE is file
      C:\Users\...\#LN00095.
350 +select * from sashelp.class
NOTE: %INCLUDE (level 1) ending.
351  );
NOTE: Table WORK.XX created, with 19 rows and 5 columns.

352  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 May 2022 21:08:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-05-10T21:08:45Z</dc:date>
    <item>
      <title>%include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812462#M320567</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*This works*/
proc sql;    
  connect to oracle (user=&amp;amp;usr
password=&amp;amp;psswd
path=&amp;amp;path
buffsize=5000); 

create table temp as
select * from connection to Oracle(
select count(*)
from schema.table
);
disconnect from oracle;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But if I add a %include and have the query inside that, then it does &lt;STRONG&gt;NOT&lt;/STRONG&gt; work. &lt;STRONG&gt;Why&lt;/STRONG&gt;?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*This works*/
proc sql;    
  connect to oracle (user=&amp;amp;usr
password=&amp;amp;psswd
path=&amp;amp;path
buffsize=5000); 

create table temp as
select * from connection to Oracle(
%include "/path/to/code/code.sas";
);
disconnect from oracle;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2022 18:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812462#M320567</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-05-10T18:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812463#M320568</link>
      <description>&lt;P&gt;Anything inside of the parentheses in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from connection to Oracle( )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;must be valid code that Oracle understands. I don't think Oracle understands %include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 18:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812463#M320568</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-10T18:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812464#M320569</link>
      <description>&lt;P&gt;Anything between the parenthesis below &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;(highlighted in red)&lt;/STRONG&gt; &lt;/FONT&gt;are passed directly to the Oracle server. The Oracle server has no knowledge of SAS so SAS command are not valid in that section. You are using SQL pass through which takes the code, passes it to the Oracle server, Oracle executes the commands and returns the results based on the query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;    
  connect to oracle (user=&amp;amp;usr
password=&amp;amp;psswd
path=&amp;amp;path
buffsize=5000); 

create table temp as
select * from connection to Oracle(
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%include "/path/to/code/code.sas";&lt;/STRONG&gt;&lt;/FONT&gt;
);
disconnect from oracle;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2022 18:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812464#M320569</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-10T18:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812465#M320570</link>
      <description>&lt;P&gt;Thank You.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 18:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812465#M320570</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-05-10T18:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812466#M320571</link>
      <description>&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 18:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812466#M320571</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-05-10T18:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812473#M320576</link>
      <description>&lt;P&gt;Try using a utility to read the file and emit the lines as code.&lt;/P&gt;
&lt;P&gt;For example you could try MODE=3 option of this macro:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/fread.sas" target="_self"&gt;%fread()&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But don't call the file a SAS file if all it contains is SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table temp as
select * from connection to Oracle(
%fread("/path/to/code/code.sql",mode=3)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: Do not expect SAS to honor line breaks in your SQL file.&amp;nbsp; So do not use those goofy -- end of the line comments.&amp;nbsp; If you want to have comments in your SQL code use real /* */ block comments.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 19:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812473#M320576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-10T19:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812495#M320585</link>
      <description>&lt;P&gt;One other option would be to put it all in the include, like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename Head TEMP;
filename Body "/path/to/code/code.sas";
filename Tail TEMP;

data _null_;
file Head; input; put _infile_;
cards4;
proc sql;    
  connect to oracle (user=&amp;amp;usr
password=&amp;amp;psswd
path=&amp;amp;path
buffsize=5000); 
create table temp as
select * from connection to Oracle(
;;;;
run;

data _null_;
file Tail; input; put _infile_;
cards4;
);
disconnect from oracle;
quit;
;;;;
run;

%include Head Body Tail / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 20:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812495#M320585</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-05-10T20:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812496#M320586</link>
      <description>&lt;P&gt;That works as well.&lt;/P&gt;
&lt;P&gt;Note you just need to have the beginning of the SAS statement in the PRE file because the %INCLUDE statement cannot be called in the middle of a SAS statement. There is no need for a POST file, you can just have that part of the statement in the program itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example you can try.&amp;nbsp; The is example is just using SASHELP dataset to demonstrate the idea.&amp;nbsp; Just update the prefix code to reference Oracle if you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=code;
filename code temp;

parmcards;
select * from sashelp.class
;

options parmcards=pre;
filename pre temp;

parmcards;
create table xx as (
;

proc sql;
%include pre code / source2;
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;347  proc sql;
348  %include pre code / source2;
NOTE: %INCLUDE (level 1) file PRE is file
      C:\Users\...\#LN00096.
349 +create table xx as (
NOTE: %INCLUDE (level 1) ending.
NOTE: %INCLUDE (level 1) file CODE is file
      C:\Users\...\#LN00095.
350 +select * from sashelp.class
NOTE: %INCLUDE (level 1) ending.
351  );
NOTE: Table WORK.XX created, with 19 rows and 5 columns.

352  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 21:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812496#M320586</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-10T21:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: %include inside Oracle Connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812510#M320594</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Anything inside of the parentheses in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from connection to Oracle( )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;must be valid code that Oracle understands. I don't think Oracle understands %include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is not that ORACLE does not understand %INCLUDE.&lt;/P&gt;
&lt;P&gt;The issue is that the SAS macro processor only recognizes %INCLUDE at a statement boundary.&amp;nbsp; You cannot use it after you have already begun the CREATE or SELECT statement.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 22:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-inside-Oracle-Connection/m-p/812510#M320594</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-10T22:52:32Z</dc:date>
    </item>
  </channel>
</rss>

