<?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: Use SQL hints in PROC SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787838#M251814</link>
    <description>&lt;P&gt;I had the strange problem that the &lt;EM&gt;preserve_comments&lt;/EM&gt; didn't work, neither when specifying it in a Libname and then USING that Libname in explicit passthrough as described &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_018/acreldb/p10zn4vxk9kydhn1uqmvflt51puq.htm#:~:text=REGISTRY%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/OPTGUIDELINES%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20*/%0A%20%20%20%20%20%20%20%20)%20%3B%20%0A%20%20quit%20%3B-,Example%202%3A%20Pass%20Content%20by%20Using%20the%20LIBNAME%20Option%20with%20a%20PROC%20SQL%20Query,-Here%20is%20a" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;(example 2):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;LIBNAME xyz ORACLE ...&amp;nbsp;PRESERVE_COMMENTS=YES;

proc sql;
connect using xyz
...
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;nor when using the &lt;EM&gt;preserve_comments&lt;/EM&gt; in Pass-Through directly as described&amp;nbsp;&lt;A href="https://support.sas.com/kb/19/205.html" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
      connect to oracle as mycon(user=testuser
                 password=testpass preserve_comments)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What DID work for me, however, was masking the comment in the explicit passthrough, this is what I ended up using:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	connect using mycon;
	select * from connection to mycon
	(
	select %STR(/)%STR(*)+PARALLEL(16) %STR(*)%STR(/) xyz...
        );
	disconnect from mycon;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The masked comment is equal to /*+parallel(16) */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took this format somewhat from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Please-explain-the-purpose-of-statement-Select-parallel-within/td-p/286505" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;. This is the only way that worked for me.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Dec 2021 18:56:26 GMT</pubDate>
    <dc:creator>SAS-Nutzer</dc:creator>
    <dc:date>2021-12-30T18:56:26Z</dc:date>
    <item>
      <title>Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787798#M251789</link>
      <description>&lt;P&gt;How can I use a SQL (Oracle) hint in Proc SQL? I try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
  select /*+ parallel (16) */ xy...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it doesn't seem to work. Is it possible to use hints in Proc SQL, or must I use an explicit pass-through for that?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787798#M251789</guid>
      <dc:creator>SAS-Nutzer</dc:creator>
      <dc:date>2021-12-30T15:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787806#M251792</link>
      <description>&lt;P&gt;Search:&amp;nbsp;&amp;nbsp;&lt;A href="https://www.google.com/search?q=%40sas.com+oracle+hints" target="_blank"&gt;https://www.google.com/search?q=%40sas.com+oracle+hints&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to tell SAS you want to pass comments to Oracle by including the preserve_comments option when connecting, otherwise *surprise* comments are treated as comments by SAS and stripped out of the code that runs.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/19/205.html" target="_blank"&gt;https://support.sas.com/kb/19/205.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For implicit passthru you can pass hints with the dataset option, ORHINTS=.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/p1uutrqh4za0sgn1c26jj7z1k6m9.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/p1uutrqh4za0sgn1c26jj7z1k6m9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 16:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787806#M251792</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T16:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787838#M251814</link>
      <description>&lt;P&gt;I had the strange problem that the &lt;EM&gt;preserve_comments&lt;/EM&gt; didn't work, neither when specifying it in a Libname and then USING that Libname in explicit passthrough as described &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_018/acreldb/p10zn4vxk9kydhn1uqmvflt51puq.htm#:~:text=REGISTRY%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C/OPTGUIDELINES%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20*/%0A%20%20%20%20%20%20%20%20)%20%3B%20%0A%20%20quit%20%3B-,Example%202%3A%20Pass%20Content%20by%20Using%20the%20LIBNAME%20Option%20with%20a%20PROC%20SQL%20Query,-Here%20is%20a" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;(example 2):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;LIBNAME xyz ORACLE ...&amp;nbsp;PRESERVE_COMMENTS=YES;

proc sql;
connect using xyz
...
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;nor when using the &lt;EM&gt;preserve_comments&lt;/EM&gt; in Pass-Through directly as described&amp;nbsp;&lt;A href="https://support.sas.com/kb/19/205.html" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
      connect to oracle as mycon(user=testuser
                 password=testpass preserve_comments)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What DID work for me, however, was masking the comment in the explicit passthrough, this is what I ended up using:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	connect using mycon;
	select * from connection to mycon
	(
	select %STR(/)%STR(*)+PARALLEL(16) %STR(*)%STR(/) xyz...
        );
	disconnect from mycon;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The masked comment is equal to /*+parallel(16) */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took this format somewhat from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Please-explain-the-purpose-of-statement-Select-parallel-within/td-p/286505" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;. This is the only way that worked for me.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 18:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787838#M251814</guid>
      <dc:creator>SAS-Nutzer</dc:creator>
      <dc:date>2021-12-30T18:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787840#M251816</link>
      <description>&lt;P&gt;Did you accidently wrap your SAS code into a macro?&amp;nbsp; The macro processor also considers /*...*/ as a comment to be ignored when generating the SAS code to run.&lt;/P&gt;
&lt;P&gt;Note you don't have to protect every character. Just protect the / before the * to prevent the macro processor from seeing the start of a block comment.&lt;/P&gt;
&lt;P&gt;Notice how the MPRINT lines from the %MYSQL does not show the "hint" but the from %MYSQL2 it does.&lt;/P&gt;
&lt;PRE&gt;783   proc sql;
784   connect to oracle;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
785   select * from connection to oracle
786   (select /*+ oracle junk */ from mytable)
787   ;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
788   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


789   %macro mysql;
790   proc sql;
791   connect to oracle;
792   select * from connection to oracle
793   (select /*+ oracle junk */ from mytable)
794   ;
795   quit;
796   %mend;
797
798   options mprint;
799   %mysql;
MPRINT(MYSQL):   proc sql;
MPRINT(MYSQL):   connect to oracle;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
MPRINT(MYSQL):   select * from connection to oracle (select from mytable) ;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
MPRINT(MYSQL):   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds



800
801   %macro mysql2;
802   proc sql;
803   connect to oracle;
804   select * from connection to oracle
805   (select %str(/)*+ oracle junk */ from mytable)
806   ;
807   quit;
808   %mend;
809
810   options mprint;
811   %mysql2;
MPRINT(MYSQL2):   proc sql;
MPRINT(MYSQL2):   connect to oracle;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
MPRINT(MYSQL2):   select * from connection to oracle (select /*+ oracle junk */ from mytable) ;
ERROR: ORACLE connection error: ORA-12560: TNS:protocol adapter error.
MPRINT(MYSQL2):   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds



&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 19:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/787840#M251816</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T19:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/800894#M315138</link>
      <description>&lt;P&gt;Although many folks who respond about preserve_comments are looking at the code snippet given, in real world situations these SQL statements are often part of SAS macros.&amp;nbsp; To ensure the comments for parallelism get passed, you should try escaping them as follows and compare the run-times to see if it makes a difference, such as:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; connect to ....&amp;nbsp; ....readbuff=8000 preserver_comments=Y ..... ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; create work.mytable(compress=yes) as select * from connection to Oracle (&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select %str(/)%str(*)+ PARALLEL(4) %str(*)%str(/)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field1, field2, field3, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from oracle_table_source&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where abc = blah&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; );&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;disconnect from Oracle;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 16:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/800894#M315138</guid>
      <dc:creator>doogie64</dc:creator>
      <dc:date>2022-03-08T16:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use SQL hints in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/800899#M315143</link>
      <description>&lt;P&gt;You don't need to protect both the / and *.&amp;nbsp;&amp;nbsp;Just protect one so the result does not look like an actual block comment to the macro processor.&lt;/P&gt;
&lt;P&gt;So any of these will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%str(/)*+ PARALLEL(4) *%str(/)
/%str(*)+ PARALLEL(4) %str(*)/
%str(/)*+ PARALLEL(4) %str(*)/
/%str(*)+ PARALLEL(4) *%str(/)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 16:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SQL-hints-in-PROC-SQL/m-p/800899#M315143</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-08T16:44:09Z</dc:date>
    </item>
  </channel>
</rss>

