<?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: Error: Literal contains unmatched quote in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866757#M342318</link>
    <description>&lt;P&gt;Looks to me like that error message is coming from the %PUT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put valore location_description ------&amp;gt;&amp;amp;location_description1.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put valore location_description ------&amp;gt;%bquote(&amp;amp;location_description1.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can replicate the error message with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    %macro foo() ;
2    data _null_ ;
3      call symputx("foo","O'Henry") ;
4    run ;
5    %put &amp;amp;foo ;
6    %mend foo ;
7    %foo()
MPRINT(FOO):   data _null_ ;
MPRINT(FOO):   call symputx("foo","O'Henry") ;
MPRINT(FOO):   run ;


ERROR: Literal contains unmatched quote.
O'Henry'
ERROR: The macro FOO will stop executing.
&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Mar 2023 16:20:30 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-03-28T16:20:30Z</dc:date>
    <item>
      <title>Error: Literal contains unmatched quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866749#M342315</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have this macro SAS:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro aggiorna(id=);&lt;BR /&gt;proc sql;&lt;BR /&gt;select distinct id,LOCATION_DESCRIPTION1 into :id ,:location_description1&lt;BR /&gt;from lo1 &lt;BR /&gt;where id=&amp;amp;id.;&lt;BR /&gt;quit;&lt;BR /&gt;%put valore id ------&amp;gt;&amp;amp;id.;&lt;BR /&gt;%put valore location_description ------&amp;gt;&amp;amp;location_description1.;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;UPDATE a2.inspection SET location_description =%unquote("&amp;amp;LOCATION_DESCRIPTION1.") WHERE ID = &amp;amp;id.;&lt;BR /&gt;quit;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table LOCATION as &lt;BR /&gt;select distinct id&lt;BR /&gt;from lo1 &lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;data _null_;&lt;BR /&gt;set LOCATION(OBS=1);&lt;BR /&gt;call execute('%nrstr(%aggiorna(id='!!id!!'));');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I must update the column in the dataset with the value that I have in my dataset, but che macrovariable&amp;nbsp;&amp;amp;location_description1. contains value with apostrophe and I receive this error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Literal contains unmatched quote.&lt;/P&gt;
&lt;P&gt;For example, value macro&amp;nbsp; &amp;amp;location_description1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PANTANO D'AVIO'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I don't find a solution.&lt;/P&gt;
&lt;P&gt;How is possibile resolve my error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try use different function for example %nrquote or %bquote but I don't resolve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 15:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866749#M342315</guid>
      <dc:creator>dipand</dc:creator>
      <dc:date>2023-03-28T15:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Literal contains unmatched quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866753#M342317</link>
      <description>&lt;P&gt;It is not clear what you are trying to do and why you are trying to store data into macro variables just so you can then move it back into data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the easiest solution is to add the actual quotes to the macro variable when it is created. Then you will not have problems using the macro variable value in code (so you won't need to use either the %BQUOTE() or&amp;nbsp; the %UNQUOTE() function).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pass a single quote (aka apostrophe) as the optional second argument to QUOTE() and the value will be quoted with single quotes so that any &amp;amp; or % characters will also be protected from being used by the macro processor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
%let location_description1=' ';
select quote(trim(LOCATION_DESCRIPTION1),"'")
  into :location_description1
  from lo1
  where id=&amp;amp;id.
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when you use the macro variable there is no need to add more quote characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;UPDATE a2.inspection
 SET location_description = &amp;amp;LOCATION_DESCRIPTION1 
 WHERE ID = &amp;amp;id.
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 16:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866753#M342317</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-28T16:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Literal contains unmatched quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866757#M342318</link>
      <description>&lt;P&gt;Looks to me like that error message is coming from the %PUT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put valore location_description ------&amp;gt;&amp;amp;location_description1.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put valore location_description ------&amp;gt;%bquote(&amp;amp;location_description1.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can replicate the error message with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    %macro foo() ;
2    data _null_ ;
3      call symputx("foo","O'Henry") ;
4    run ;
5    %put &amp;amp;foo ;
6    %mend foo ;
7    %foo()
MPRINT(FOO):   data _null_ ;
MPRINT(FOO):   call symputx("foo","O'Henry") ;
MPRINT(FOO):   run ;


ERROR: Literal contains unmatched quote.
O'Henry'
ERROR: The macro FOO will stop executing.
&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2023 16:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Literal-contains-unmatched-quote/m-p/866757#M342318</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-28T16:20:30Z</dc:date>
    </item>
  </channel>
</rss>

