<?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: Problem of single quotes in a PROC SQL inside a macro program in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11584#M1400</link>
    <description>I'm not sure why you have the %str in the %let statement, but if you keep that then you need to change your insert statement to:&lt;BR /&gt;
&lt;BR /&gt;
insert into work.matrix_state (id_state, state_name) values (2, %unquote(&amp;amp;var1));&lt;BR /&gt;
&lt;BR /&gt;
and that should work for you.&lt;BR /&gt;
Michelle</description>
    <pubDate>Thu, 17 Apr 2008 15:56:43 GMT</pubDate>
    <dc:creator>Michelle_sas</dc:creator>
    <dc:date>2008-04-17T15:56:43Z</dc:date>
    <item>
      <title>Problem of single quotes in a PROC SQL inside a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11582#M1398</link>
      <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
I have a problem with singles quotes in a PROC SQL inside a macro program. I have a macro-variable named matrix_state_name__1 which contains value : plats cuisines&lt;BR /&gt;
 and I want send this value in a Oracle base via PROC SQL.&lt;BR /&gt;
&amp;amp;column_tmp.__&amp;amp;j_ is returned by another macro and it contains, in this example, the value :&lt;BR /&gt;
matrix_state_name__1&lt;BR /&gt;
&lt;BR /&gt;
var is the variable to be inserted in Oracle table, it contains well the value between quotes which is transmitted to proc sql, but a run-time, the log returns an error.&lt;BR /&gt;
&lt;BR /&gt;
I have SAS Enterprise Guide 4.1 (4.1.0.500) with SAS V9.&lt;BR /&gt;
&lt;BR /&gt;
Here is the code that permit you to test the problem :&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
____________________________________________&lt;BR /&gt;
OPTIONS MLOGIC MPRINT SYMBOLGEN;&lt;BR /&gt;
&lt;BR /&gt;
/*Definition and initialization of variables*/&lt;BR /&gt;
%let matrix_state_name__1 = plats cuisines;&lt;BR /&gt;
%let column_tmp = matrix_state_name;&lt;BR /&gt;
%let j_ = 1; /* it is a value used for a %do loop*/&lt;BR /&gt;
%let var = &amp;amp;column_tmp.__&amp;amp;j_;&lt;BR /&gt;
%put var is : **&amp;amp;var**;&lt;BR /&gt;
%put value of var : **&amp;amp;&amp;amp;&amp;amp;var**;&lt;BR /&gt;
%let var1 = %str(%'&amp;amp;&amp;amp;&amp;amp;var%');&lt;BR /&gt;
%put value of var1 : **&amp;amp;var1**;&lt;BR /&gt;
&lt;BR /&gt;
/* Creation of the table in which we want insert data*/&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table matrix_state (id_state num(10), state_name char(20));&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* This macro does not function because of single quotes are not well transmitted (cf log) */&lt;BR /&gt;
%macro insert1;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	insert into work.matrix_state (id_state, state_name) values (2, &amp;amp;var1);&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%insert1;&lt;BR /&gt;
&lt;BR /&gt;
/* In this testing proc sql, the insertion works well, because the value to be inserted is defined and between quotes in the sql request itself*/&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	insert into work.matrix_state (id_state, state_name) values (6, 'plat cuisine');&lt;BR /&gt;
quit;&lt;BR /&gt;
____________________________________________&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help.</description>
      <pubDate>Thu, 17 Apr 2008 13:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11582#M1398</guid>
      <dc:creator>raf64flo</dc:creator>
      <dc:date>2008-04-17T13:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem of single quotes in a PROC SQL inside a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11583#M1399</link>
      <description>What is odd if you look in the global symbol table the macro variables that you created do not have single quotes.&lt;BR /&gt;
&lt;BR /&gt;
data macrovars;&lt;BR /&gt;
  set sashelp.vmacro;&lt;BR /&gt;
  if upcase(name)=:'VAR';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*********&lt;BR /&gt;
&lt;BR /&gt;
I tried this and it worked you may have to change you variable initialization to conform to your program&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   n=1;&lt;BR /&gt;
   var='plats cuisines 2';  &lt;BR /&gt;
   call symput('var'||strip(put(n,8.)),"'"||strip(var)||"'");&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 17 Apr 2008 15:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11583#M1399</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2008-04-17T15:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem of single quotes in a PROC SQL inside a macro program</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11584#M1400</link>
      <description>I'm not sure why you have the %str in the %let statement, but if you keep that then you need to change your insert statement to:&lt;BR /&gt;
&lt;BR /&gt;
insert into work.matrix_state (id_state, state_name) values (2, %unquote(&amp;amp;var1));&lt;BR /&gt;
&lt;BR /&gt;
and that should work for you.&lt;BR /&gt;
Michelle</description>
      <pubDate>Thu, 17 Apr 2008 15:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-of-single-quotes-in-a-PROC-SQL-inside-a-macro-program/m-p/11584#M1400</guid>
      <dc:creator>Michelle_sas</dc:creator>
      <dc:date>2008-04-17T15:56:43Z</dc:date>
    </item>
  </channel>
</rss>

