<?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 SQL, Macro variable and WHERE clause in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616943#M18966</link>
    <description>&lt;P&gt;Hi, I'm actually having a problem with a macro variable in a Proc SQL statement. Here's my code for the creation of the variable and the SQL statement. I'll use fictive data, but the essential is there. The problem is when I try to recall the variable in the where clause on the second SQL statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get a whole lot of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space&lt;BR /&gt;between a quoted string and the succeeding identifier is recommended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit 1:&lt;/P&gt;&lt;P&gt;But it puts an red x like an error, and my people won't allow to run a program which generates an "error" though it isn't counted as one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL noprint;&lt;BR /&gt;Connect to oracle ();&lt;BR /&gt;Select distinct data into: macro_var separated by " ',' "&lt;/P&gt;&lt;P&gt;from connection to oracle&lt;BR /&gt;(select data&lt;BR /&gt;from table1&lt;BR /&gt;where ( maturitydate &amp;gt; today&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put %nrbquote(')&amp;amp;macro_var%nrbquote(');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here my var outputs 'asdgsd','asdsgsg','affdg'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;Connect to oracle();&lt;/P&gt;&lt;P&gt;Create table Ind as&lt;/P&gt;&lt;P&gt;Select *&lt;/P&gt;&lt;P&gt;From connection to oracle&lt;/P&gt;&lt;P&gt;(&lt;BR /&gt;Select *&lt;/P&gt;&lt;P&gt;From table2&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Where (data in (%nrbquote(')&amp;amp;macro_var%nrbquote(')))&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;);&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 16:10:30 GMT</pubDate>
    <dc:creator>KBou</dc:creator>
    <dc:date>2020-01-13T16:10:30Z</dc:date>
    <item>
      <title>SQL, Macro variable and WHERE clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616943#M18966</link>
      <description>&lt;P&gt;Hi, I'm actually having a problem with a macro variable in a Proc SQL statement. Here's my code for the creation of the variable and the SQL statement. I'll use fictive data, but the essential is there. The problem is when I try to recall the variable in the where clause on the second SQL statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get a whole lot of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space&lt;BR /&gt;between a quoted string and the succeeding identifier is recommended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit 1:&lt;/P&gt;&lt;P&gt;But it puts an red x like an error, and my people won't allow to run a program which generates an "error" though it isn't counted as one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL noprint;&lt;BR /&gt;Connect to oracle ();&lt;BR /&gt;Select distinct data into: macro_var separated by " ',' "&lt;/P&gt;&lt;P&gt;from connection to oracle&lt;BR /&gt;(select data&lt;BR /&gt;from table1&lt;BR /&gt;where ( maturitydate &amp;gt; today&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put %nrbquote(')&amp;amp;macro_var%nrbquote(');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here my var outputs 'asdgsd','asdsgsg','affdg'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;Connect to oracle();&lt;/P&gt;&lt;P&gt;Create table Ind as&lt;/P&gt;&lt;P&gt;Select *&lt;/P&gt;&lt;P&gt;From connection to oracle&lt;/P&gt;&lt;P&gt;(&lt;BR /&gt;Select *&lt;/P&gt;&lt;P&gt;From table2&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Where (data in (%nrbquote(')&amp;amp;macro_var%nrbquote(')))&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;);&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 16:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616943#M18966</guid>
      <dc:creator>KBou</dc:creator>
      <dc:date>2020-01-13T16:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL, Macro variable and WHERE clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616946#M18967</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269031"&gt;@KBou&lt;/a&gt;&amp;nbsp; You can keep it very simple by using QUOTE function without having to use any macro quoting for your case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Select distinct quote(data) into: macro_var separated by  ',' &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you can call the macro reference later like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Where data in (&amp;amp;macro_var)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 16:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616946#M18967</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-13T16:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: SQL, Macro variable and WHERE clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616956#M18970</link>
      <description>Ty sir, very appreciated. Didn't knew about the quote function. Wasn't used in any of our codes yet, but certainly will be since i generate every macro variable by SQL.</description>
      <pubDate>Mon, 13 Jan 2020 16:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-Macro-variable-and-WHERE-clause/m-p/616956#M18970</guid>
      <dc:creator>KBou</dc:creator>
      <dc:date>2020-01-13T16:22:28Z</dc:date>
    </item>
  </channel>
</rss>

