<?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 How to add quotes to a macro argument that is used in PROC SQL WHERE clause. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497204#M72453</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro that I am using to run some PROC SQL code. I am using the macro's input both in creating the output table name and in the SQL's WHERE clause. When I run the macro, I don't put quotes around the input string because that would not work when creating the table name. However, I need the input string to have quotes around it for the WHERE clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the situation below. I've searched around a bunch for solutions to this and none of them seem to be working. I'm still relatively new to SAS, so I really appreciate anyone's advice on this, or if you have a link to a similar solution that would work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test_example (subject_name);
PROC SQL;
CREATE TABLE WORK.Report_&amp;amp;subject_name. AS

SELECT *
FROM LIB.TABLE_NAME
WHERE FIELD1 = &amp;amp;subject_name.  /*Tried this.*/
WHERE FIELD1 = CAT("'", &amp;amp;subject_name., "'")  /*Tried this too.*/
WHERE FIELD1 = "'"||&amp;amp;subject_name.||"'"  /*Tried this as well.*/
;
QUIT;
%mend;

%test_example(Item1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I could just create a second input in the macro, one that has single quotes around the same input string repeated, but I feel like there must be a better, simpler solution than that. I am using SAS Enterprise Guide 7.15.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Ben&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 00:28:41 GMT</pubDate>
    <dc:creator>bgatch</dc:creator>
    <dc:date>2018-09-20T00:28:41Z</dc:date>
    <item>
      <title>How to add quotes to a macro argument that is used in PROC SQL WHERE clause.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497204#M72453</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro that I am using to run some PROC SQL code. I am using the macro's input both in creating the output table name and in the SQL's WHERE clause. When I run the macro, I don't put quotes around the input string because that would not work when creating the table name. However, I need the input string to have quotes around it for the WHERE clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the situation below. I've searched around a bunch for solutions to this and none of them seem to be working. I'm still relatively new to SAS, so I really appreciate anyone's advice on this, or if you have a link to a similar solution that would work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test_example (subject_name);
PROC SQL;
CREATE TABLE WORK.Report_&amp;amp;subject_name. AS

SELECT *
FROM LIB.TABLE_NAME
WHERE FIELD1 = &amp;amp;subject_name.  /*Tried this.*/
WHERE FIELD1 = CAT("'", &amp;amp;subject_name., "'")  /*Tried this too.*/
WHERE FIELD1 = "'"||&amp;amp;subject_name.||"'"  /*Tried this as well.*/
;
QUIT;
%mend;

%test_example(Item1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I could just create a second input in the macro, one that has single quotes around the same input string repeated, but I feel like there must be a better, simpler solution than that. I am using SAS Enterprise Guide 7.15.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Ben&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 00:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497204#M72453</guid>
      <dc:creator>bgatch</dc:creator>
      <dc:date>2018-09-20T00:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add quotes to a macro argument that is used in PROC SQL WHERE clause.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497215#M72454</link>
      <description>&lt;P&gt;did you try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; FIELD1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; "&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;subject_name"&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497215#M72454</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-20T02:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to add quotes to a macro argument that is used in PROC SQL WHERE clause.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497223#M72455</link>
      <description>&lt;P&gt;&lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;SPAN class="login-bold"&gt;Hello novinosrin, thank you so much!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;SPAN class="login-bold"&gt;That resolves correctly and works to pull the data! Appreciate your help!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497223#M72455</guid>
      <dc:creator>bgatch</dc:creator>
      <dc:date>2018-09-20T02:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to add quotes to a macro argument that is used in PROC SQL WHERE clause.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497225#M72456</link>
      <description>&lt;P&gt;Welcome to the SAS forum and I'm glad issue has been resolved. May i request you to mark the solution and close the thread if you don't mind plz.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-quotes-to-a-macro-argument-that-is-used-in-PROC-SQL/m-p/497225#M72456</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-20T02:57:54Z</dc:date>
    </item>
  </channel>
</rss>

