<?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: Macro variable containing single quotes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195536#M36802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So the next statement is %do - it's part of a macro.&amp;nbsp;&amp;nbsp; And the Where statement gets built up, this macro is iterated and builds up multiple fieldnames each iteration so I can't just build out the where statement with the variable directly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2015 20:01:50 GMT</pubDate>
    <dc:creator>MitchHolt</dc:creator>
    <dc:date>2015-05-28T20:01:50Z</dc:date>
    <item>
      <title>Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195531#M36797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;I'm completely lost - i'm sure this question has been asked and answered before but i can't make sense of what I've read so far.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;I have a macro that is building out a proc sql statement.&amp;nbsp; I need the where statement to include matched single quotes.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;I have this now:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt; WhereSt= "&amp;amp;WhereSt &amp;amp;FieldName &amp;lt;&amp;gt; '''' ";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;And the result should be something like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;Where Agent &amp;lt;&amp;gt; ''&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;How on earth do I do that?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 18:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195531#M36797</guid>
      <dc:creator>MitchHolt</dc:creator>
      <dc:date>2015-05-28T18:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195532#M36798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/" title="http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/"&gt;http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195532#M36798</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-05-28T19:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195533#M36799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still not clear on what I'm supposed to put where - almost everything I've done still ends with an error.&amp;nbsp; The next line of code is a Do statement and I get an error Macro Keyword Do appears as text&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195533#M36799</guid>
      <dc:creator>MitchHolt</dc:creator>
      <dc:date>2015-05-28T19:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195534#M36800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Quotes and quoting is one of the most terrible things to solve and work on. The simple reason is they are used for that many goals and meanings.&lt;BR /&gt;Generating those strings with a datastep or scl is less challenging than using macro-s.&amp;nbsp; As you are saying the next statement is a DO statement (no %) you are most likely in a datastep.&lt;BR /&gt;Within that you only have the meaning of quotes for strings, but the complication is that using 2-quotes with no space in between is set back as a single one when used for the charstring.&lt;BR /&gt;Your SQL statement is having the ' ' (one space) for indicating a null-string or SAS missing. When the SQL is referring an external DBMS the NULL-values are mostly translated to&amp;nbsp; '&amp;nbsp; ' but sometimes NULL is not the same as it is&amp;nbsp; a 3 value logic not the true/false digital logic.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195534#M36800</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-05-28T19:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195535#M36801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Japp said, this can be complicated.&amp;nbsp; And you may need to remove any blanks between your single quotes.&amp;nbsp; But it doesn't need to get this complicated.&amp;nbsp; It looks like you already have some macro variables to work with, and need to construct the SQL WHERE clause.&amp;nbsp; I would expect to see something like this to add a condition about &amp;amp;FieldName to an existing WHERE clause:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where x &amp;gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %length(&amp;amp;FieldName) %then and &amp;amp;FieldName &amp;lt;&amp;gt; '';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 19:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195535#M36801</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-28T19:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195536#M36802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So the next statement is %do - it's part of a macro.&amp;nbsp;&amp;nbsp; And the Where statement gets built up, this macro is iterated and builds up multiple fieldnames each iteration so I can't just build out the where statement with the variable directly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 20:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195536#M36802</guid>
      <dc:creator>MitchHolt</dc:creator>
      <dc:date>2015-05-28T20:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195537#M36803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I changed the logic to be is not null which seems to be working - it'll take several hours for the code to fully run but I think that works and avoids all the worry about the quotes - thanks for the responses&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 20:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195537#M36803</guid>
      <dc:creator>MitchHolt</dc:creator>
      <dc:date>2015-05-28T20:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195538#M36804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use %BQUOTE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the following example using pass-through SQL, Oracle expects a date string inside single quotes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let want_date = 2015-05-01;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to oracle as dorrdb &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (path=dorrdb user=&amp;amp;NRUSER. password=&amp;amp;NRPASS.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from connection to dorrdb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from vdw.vdw_rx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where rownum &amp;lt;= 10 and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rxdate = DATE %BQUOTE('&amp;amp;WANT_DATE.')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; disconnect from dorrdb;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what Oracle sees is&amp;nbsp;&amp;nbsp; rxdate = DATE '2015-05-01'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 14:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195538#M36804</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2015-05-29T14:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable containing single quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195539#M36805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;The paper &lt;EM&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/128-29.pdf"&gt;SAS® Macro: Symbols of Frustration? %Let us help! A Guide to Debugging Macros&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;contains some good information about troubleshooting macros, including how to handle special characters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 16:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-containing-single-quotes/m-p/195539#M36805</guid>
      <dc:creator>leelee</dc:creator>
      <dc:date>2015-05-29T16:08:01Z</dc:date>
    </item>
  </channel>
</rss>

