<?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 PROC SQL passthrough versus direct call in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588034#M75889</link>
    <description>&lt;P&gt;I have two identical data structures.&amp;nbsp; One where it's most efficient to use the passthrough and another where I have to reach it directly.&amp;nbsp; This scenario is going to apply to much of my programming in the future so I want to try to pull the data as efficently as possible and recycle the actual SQL for both.&lt;/P&gt;&lt;P&gt;My idea was to put the SQL statement in a macro and call the macro in both the proc sql for the passthrough and the regular proc sql using an insert.&amp;nbsp; The issue is that the passthrough requires the statement to be enclosed in paretheses and the regualr proc sql statement will NOT allow paretheses at all.&amp;nbsp; Seems stupid, but it's got me stuck.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;%MACRO Get_table;&lt;BR /&gt;(SELECT &amp;amp;regno,&lt;/P&gt;&lt;P&gt;t1.Field1,&lt;BR /&gt;t1.Field2&lt;BR /&gt;from &amp;amp;source.thetablename t1&lt;BR /&gt;WHERE (t1.Field1 Between '0*' And '999'));&lt;BR /&gt;%Mend Get_table;&lt;/P&gt;&lt;P&gt;If I drop this into my passthrough it works great.&amp;nbsp; If I drop it into something like:&lt;/P&gt;&lt;P&gt;%MACRO RUN_CODE;&lt;BR /&gt;PROC SQL FEEDBACK;&lt;BR /&gt;INSERT INTO WORK.LOCAL_thetablename&lt;BR /&gt;%Get_table;&lt;BR /&gt;QUIT;&lt;BR /&gt;%mend RUN_CODE;&lt;/P&gt;&lt;P&gt;I get an error because of the parentheses -&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: ), ','.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I use the same SQL code in both a passthrough and regular proc SQL statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Sep 2019 21:38:44 GMT</pubDate>
    <dc:creator>mikeydubs23</dc:creator>
    <dc:date>2019-09-11T21:38:44Z</dc:date>
    <item>
      <title>PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588034#M75889</link>
      <description>&lt;P&gt;I have two identical data structures.&amp;nbsp; One where it's most efficient to use the passthrough and another where I have to reach it directly.&amp;nbsp; This scenario is going to apply to much of my programming in the future so I want to try to pull the data as efficently as possible and recycle the actual SQL for both.&lt;/P&gt;&lt;P&gt;My idea was to put the SQL statement in a macro and call the macro in both the proc sql for the passthrough and the regular proc sql using an insert.&amp;nbsp; The issue is that the passthrough requires the statement to be enclosed in paretheses and the regualr proc sql statement will NOT allow paretheses at all.&amp;nbsp; Seems stupid, but it's got me stuck.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;%MACRO Get_table;&lt;BR /&gt;(SELECT &amp;amp;regno,&lt;/P&gt;&lt;P&gt;t1.Field1,&lt;BR /&gt;t1.Field2&lt;BR /&gt;from &amp;amp;source.thetablename t1&lt;BR /&gt;WHERE (t1.Field1 Between '0*' And '999'));&lt;BR /&gt;%Mend Get_table;&lt;/P&gt;&lt;P&gt;If I drop this into my passthrough it works great.&amp;nbsp; If I drop it into something like:&lt;/P&gt;&lt;P&gt;%MACRO RUN_CODE;&lt;BR /&gt;PROC SQL FEEDBACK;&lt;BR /&gt;INSERT INTO WORK.LOCAL_thetablename&lt;BR /&gt;%Get_table;&lt;BR /&gt;QUIT;&lt;BR /&gt;%mend RUN_CODE;&lt;/P&gt;&lt;P&gt;I get an error because of the parentheses -&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: ), ','.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I use the same SQL code in both a passthrough and regular proc SQL statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588034#M75889</guid>
      <dc:creator>mikeydubs23</dc:creator>
      <dc:date>2019-09-11T21:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588051#M75890</link>
      <description>&lt;P&gt;It would be helpful if you could explain what you are doing here. Are you loading SAS data into the external database or not? If you are then the following comments are relevant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PASSTHRU mode cannot reference SAS data as everything is happening in your external database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to insert SAS data into an external dataset in my experience is PROC DATASETS using an APPEND statement using a database LIBNAME.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 22:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588051#M75890</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-11T22:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588234#M75898</link>
      <description>&lt;P&gt;I am not loading data, only retrieving/pulling.&amp;nbsp; What I'm doing is setting up a blank table in the work environment using a proc sql statement.&amp;nbsp; Next I'm running a simple passthrough (Sybase) where I have all of the necessary parts of the passthrough except the actual SQL statement which I've place in a macro.&amp;nbsp; I use the macro instead of the actual SQL statement.&amp;nbsp; Since the macro contains the opening and closing parentheses, it works and inserts into the blank table.&lt;/P&gt;&lt;P&gt;Next, I run the direct proc sql:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC SQL FEEDBACK;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;INSERT INTO WORK.LOCAL_thetablename&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%Get_table;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and it fails because of the parentheses.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I pass the data-source&amp;nbsp;via a macro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The idea is to avoid writing the same SQL code twice in a program so that I (or a future developer) can be sure I'm leveraging or applying the same code to these separate databases.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I know it works when I remove the parentheses so my question is how can I accommodate&amp;nbsp;both the passthrough and direct message if the passthrough requires the parentheses and the direct method breaks with parentheses.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 13:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588234#M75898</guid>
      <dc:creator>mikeydubs23</dc:creator>
      <dc:date>2019-09-12T13:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588238#M75899</link>
      <description>&lt;P&gt;Huh?&amp;nbsp; Don't put the ( ) in the text to be repeated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sql_code = select ..... ;
proc sql;
* Just in SAS ;
&amp;amp;sql_code ;
* Push into database ;
connect to oracle ;
select * from connection to oracle
  (&amp;amp;sql_code)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I think you will find that there are enough difference between SAS syntax and whatever flavor of SQL your external database is using that you will either want separate queries.&lt;/P&gt;
&lt;P&gt;Or let SAS figure it out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname saslib 'my directory';
libname oralib oracle ... ;
proc sql;
select * from saslib.mydata ;
select * from oralib.mydata ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 13:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588238#M75899</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-12T13:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588244#M75900</link>
      <description>I tried that, but maybe the issue is that I was putting the SQL code in a macro instead of a macro variable. I'll try that and see if that's more successful.</description>
      <pubDate>Thu, 12 Sep 2019 14:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588244#M75900</guid>
      <dc:creator>mikeydubs23</dc:creator>
      <dc:date>2019-09-12T14:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588245#M75901</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115249"&gt;@mikeydubs23&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I tried that, but maybe the issue is that I was putting the SQL code in a macro instead of a macro variable. I'll try that and see if that's more successful.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A macro should work. Just make sure the macro doesn't generate any semi-colons.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 14:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588245#M75901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-12T14:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL passthrough versus direct call</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588315#M75903</link>
      <description>I did ultimately use the macro instead of the macro variable and the issue was that the trailing semi-colon that I thought was necessary after the sql statement but before the %mend statement was the problem. I thought the semi-colon was ending the statement not part of the SQL text but your last suggestion helped me realize that the semi-colon was being included.&lt;BR /&gt;Thansk</description>
      <pubDate>Thu, 12 Sep 2019 16:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-passthrough-versus-direct-call/m-p/588315#M75903</guid>
      <dc:creator>mikeydubs23</dc:creator>
      <dc:date>2019-09-12T16:47:25Z</dc:date>
    </item>
  </channel>
</rss>

