<?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: Using a Macro to pass dynamic data to DB2 in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6147#M1950</link>
    <description>Hi:&lt;BR /&gt;
  I always find it useful to figure out how something works without involving the SAS Macro facility, before I try to introduce anything macro into the code.&lt;BR /&gt;
  &lt;BR /&gt;
For example, let's say I have this data, WORK.ALLCOMMENT:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   NAME   COMMENT&lt;BR /&gt;
   ----   ------------------------------------------------&lt;BR /&gt;
   alan   Good course. Needs an email example.   &lt;BR /&gt;
   barb   I think the course could have been a day longer.   &lt;BR /&gt;
   carl   Does all of this work on the mainframe?   &lt;BR /&gt;
   dan   The examples were very good.   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
How would I use the INSERT statement to add character data with an apostrophe or quote in the COMMENT variable value??&lt;BR /&gt;
This is the syntax I'd use:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  insert into work.allcomment&lt;BR /&gt;
    values("zach","Test Comment with test's of apos'trophe");&lt;BR /&gt;
quit;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
  title "New Row";&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Which results in this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
New Row                                                                                                          &lt;BR /&gt;
  &lt;BR /&gt;
Obs    name    comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     alan    Good course. Needs an email example.&lt;BR /&gt;
 2     barb    I think the course could have been a day longer.&lt;BR /&gt;
 3     carl    Does all of this work on the mainframe?&lt;BR /&gt;
 4     dan     The examples were very good.&lt;BR /&gt;
 5     zach    Test Comment with test's of apos'trophe&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
So now, the question becomes, how would I modify the INSERT statement to use macro variables to supply the text strings for NAME and COMMENT?? Assuming that I have created the following macro variables &amp;amp;INAME and &amp;amp;ICOMMENT (no matter how I created them -- with INTO or with CALL SYMPUT), this syntax worked for me:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
** my macro variables;&lt;BR /&gt;
***************************************************************;&lt;BR /&gt;
*** Macro                                                      ;&lt;BR /&gt;
*** Variable  Value                                            ;&lt;BR /&gt;
*** &amp;amp;INAME    eliza                                            ;&lt;BR /&gt;
*** &amp;amp;ICOMMENT This was the best course I've ever taken.        ;&lt;BR /&gt;
************************************************************** ;&lt;BR /&gt;
    &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  insert into work.allcomment&lt;BR /&gt;
    values("&amp;amp;iname","&amp;amp;icomment");&lt;BR /&gt;
quit;&lt;BR /&gt;
   &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
  title "New Row with quote";&lt;BR /&gt;
run;&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And I get these results (If I run this code after I add Zach's info:&lt;BR /&gt;
[pre]&lt;BR /&gt;
New Row with quote&lt;BR /&gt;
                                                                                       &lt;BR /&gt;
Obs    name     comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     alan     Good course. Needs an email example.&lt;BR /&gt;
 2     barb     I think the course could have been a day longer.&lt;BR /&gt;
 3     carl     Does all of this work on the mainframe?&lt;BR /&gt;
 4     dan      The examples were very good.&lt;BR /&gt;
 5     zach     Test Comment with test's of apos'trophe&lt;BR /&gt;
 6     eliza    This was the best course I've ever taken.&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Of course, I have very simple data with very simple quotes. All my quotes in the character string are single quotes and so I am able, in the INSERT, to just use double quotes around the macro variable because my single quotes inside the double quotes will correctly resolve into 1 character string. It would be a mistake to leave off the double quotes or to only use a macro quoting function in place of the double quotes, because the working SAS program needs to have a quoted string to insert a character value into a table....and I couldn't use single quotes around my string because 1) my string contains single quotes and 2) I need the macro variables to resolve and they won't resolve in single quotes.&lt;BR /&gt;
&lt;BR /&gt;
If you have a more complicated quoting situation, such as mixed single and double quotes in your character variable value, then you may need to get into more complex quoting functions. I know of no better resource on quoting functions than the macro documentation, which contains several tables that show the list of quoting functions and when each quoting function is best used.&lt;BR /&gt;
&lt;BR /&gt;
Or, you could contact Tech Support with your specific data/code question.&lt;BR /&gt;
&lt;BR /&gt;
One last thought. In order to do an INTO to create your macro variables, that implies that you have the data you want already in a SAS dataset. Is there a particular reason you want to use the Macro facility??? For example, let's say that there's a file called WORK.NEWCOMMENT, which contains the following observations:&lt;BR /&gt;
[pre]&lt;BR /&gt;
WORK.NEWCOMMENT &lt;BR /&gt;
  &lt;BR /&gt;
Obs     name     comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     eliza     This was the best course I've ever taken.&lt;BR /&gt;
 2     frank     None&lt;BR /&gt;
 3     george    No Comment&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
And you only want to add Eliza's information to the ALLCOMMENT file -- then this syntax works without using SAS Macro at all:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
  &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  INSERT INTO work.allcomment&lt;BR /&gt;
  SELECT * from work.newcomment&lt;BR /&gt;
  where comment ne "None" and comment ne "No Comment";&lt;BR /&gt;
quit;&lt;BR /&gt;
  &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
cynthia</description>
    <pubDate>Fri, 04 Jan 2008 19:40:20 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-01-04T19:40:20Z</dc:date>
    <item>
      <title>Using a Macro to pass dynamic data to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6145#M1948</link>
      <description>Hi all&lt;BR /&gt;
&lt;BR /&gt;
I have created a macro to pass data into a DB2 table.  The macro creates a number of variables using the Select and INTO syntax e.g Part1:-PartN.&lt;BR /&gt;
&lt;BR /&gt;
The issue I am having is that when I try and update a DB2 table and the contents of the variable has an apostrope in it, the macro fails.  E.g " Driver's manual "  - the 's causes the failure.&lt;BR /&gt;
&lt;BR /&gt;
I tried using %BQUOTE but that simply reads up to Driver and then the log says&lt;BR /&gt;
 ILLEGAL SYMBOL "'S MANUAL&lt;BR /&gt;
&lt;BR /&gt;
I even tried assigning the output of %BQuote to a variable and using that variable to update the table dynamically but that does not work as well.&lt;BR /&gt;
&lt;BR /&gt;
How can I get rid of the apostrophe ?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Shelton.

Message was edited by: sdcruz</description>
      <pubDate>Fri, 04 Jan 2008 11:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6145#M1948</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-04T11:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Macro to pass dynamic data to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6146#M1949</link>
      <description>Could you provide a more specific example of the code?

Message was edited by: Chuck</description>
      <pubDate>Fri, 04 Jan 2008 14:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6146#M1949</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-04T14:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Macro to pass dynamic data to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6147#M1950</link>
      <description>Hi:&lt;BR /&gt;
  I always find it useful to figure out how something works without involving the SAS Macro facility, before I try to introduce anything macro into the code.&lt;BR /&gt;
  &lt;BR /&gt;
For example, let's say I have this data, WORK.ALLCOMMENT:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   NAME   COMMENT&lt;BR /&gt;
   ----   ------------------------------------------------&lt;BR /&gt;
   alan   Good course. Needs an email example.   &lt;BR /&gt;
   barb   I think the course could have been a day longer.   &lt;BR /&gt;
   carl   Does all of this work on the mainframe?   &lt;BR /&gt;
   dan   The examples were very good.   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
How would I use the INSERT statement to add character data with an apostrophe or quote in the COMMENT variable value??&lt;BR /&gt;
This is the syntax I'd use:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  insert into work.allcomment&lt;BR /&gt;
    values("zach","Test Comment with test's of apos'trophe");&lt;BR /&gt;
quit;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
  title "New Row";&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Which results in this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
New Row                                                                                                          &lt;BR /&gt;
  &lt;BR /&gt;
Obs    name    comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     alan    Good course. Needs an email example.&lt;BR /&gt;
 2     barb    I think the course could have been a day longer.&lt;BR /&gt;
 3     carl    Does all of this work on the mainframe?&lt;BR /&gt;
 4     dan     The examples were very good.&lt;BR /&gt;
 5     zach    Test Comment with test's of apos'trophe&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
So now, the question becomes, how would I modify the INSERT statement to use macro variables to supply the text strings for NAME and COMMENT?? Assuming that I have created the following macro variables &amp;amp;INAME and &amp;amp;ICOMMENT (no matter how I created them -- with INTO or with CALL SYMPUT), this syntax worked for me:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
** my macro variables;&lt;BR /&gt;
***************************************************************;&lt;BR /&gt;
*** Macro                                                      ;&lt;BR /&gt;
*** Variable  Value                                            ;&lt;BR /&gt;
*** &amp;amp;INAME    eliza                                            ;&lt;BR /&gt;
*** &amp;amp;ICOMMENT This was the best course I've ever taken.        ;&lt;BR /&gt;
************************************************************** ;&lt;BR /&gt;
    &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  insert into work.allcomment&lt;BR /&gt;
    values("&amp;amp;iname","&amp;amp;icomment");&lt;BR /&gt;
quit;&lt;BR /&gt;
   &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
  title "New Row with quote";&lt;BR /&gt;
run;&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And I get these results (If I run this code after I add Zach's info:&lt;BR /&gt;
[pre]&lt;BR /&gt;
New Row with quote&lt;BR /&gt;
                                                                                       &lt;BR /&gt;
Obs    name     comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     alan     Good course. Needs an email example.&lt;BR /&gt;
 2     barb     I think the course could have been a day longer.&lt;BR /&gt;
 3     carl     Does all of this work on the mainframe?&lt;BR /&gt;
 4     dan      The examples were very good.&lt;BR /&gt;
 5     zach     Test Comment with test's of apos'trophe&lt;BR /&gt;
 6     eliza    This was the best course I've ever taken.&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Of course, I have very simple data with very simple quotes. All my quotes in the character string are single quotes and so I am able, in the INSERT, to just use double quotes around the macro variable because my single quotes inside the double quotes will correctly resolve into 1 character string. It would be a mistake to leave off the double quotes or to only use a macro quoting function in place of the double quotes, because the working SAS program needs to have a quoted string to insert a character value into a table....and I couldn't use single quotes around my string because 1) my string contains single quotes and 2) I need the macro variables to resolve and they won't resolve in single quotes.&lt;BR /&gt;
&lt;BR /&gt;
If you have a more complicated quoting situation, such as mixed single and double quotes in your character variable value, then you may need to get into more complex quoting functions. I know of no better resource on quoting functions than the macro documentation, which contains several tables that show the list of quoting functions and when each quoting function is best used.&lt;BR /&gt;
&lt;BR /&gt;
Or, you could contact Tech Support with your specific data/code question.&lt;BR /&gt;
&lt;BR /&gt;
One last thought. In order to do an INTO to create your macro variables, that implies that you have the data you want already in a SAS dataset. Is there a particular reason you want to use the Macro facility??? For example, let's say that there's a file called WORK.NEWCOMMENT, which contains the following observations:&lt;BR /&gt;
[pre]&lt;BR /&gt;
WORK.NEWCOMMENT &lt;BR /&gt;
  &lt;BR /&gt;
Obs     name     comment&lt;BR /&gt;
  &lt;BR /&gt;
 1     eliza     This was the best course I've ever taken.&lt;BR /&gt;
 2     frank     None&lt;BR /&gt;
 3     george    No Comment&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
And you only want to add Eliza's information to the ALLCOMMENT file -- then this syntax works without using SAS Macro at all:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
  &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  INSERT INTO work.allcomment&lt;BR /&gt;
  SELECT * from work.newcomment&lt;BR /&gt;
  where comment ne "None" and comment ne "No Comment";&lt;BR /&gt;
quit;&lt;BR /&gt;
  &lt;BR /&gt;
proc print data=work.allcomment;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 04 Jan 2008 19:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-a-Macro-to-pass-dynamic-data-to-DB2/m-p/6147#M1950</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-01-04T19:40:20Z</dc:date>
    </item>
  </channel>
</rss>

