<?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 SQL to create a macro variable with &amp;quot;;&amp;quot; in the values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750044#M235849</link>
    <description>&lt;P&gt;Not the most useful macro variable I've seen. If you only want one value (from the first record only as the current sql is written) it would be just as easy to do manually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s suggestion works for code as written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you intend to put more of the values into that macro variable you will want to seriously consider whether a semicolon is appropriate at all as you may be jumping through multiple hoops to use it. Other problems result when using commas for separating values.&lt;/P&gt;
&lt;P&gt;It might help to show exactly how you expect to use that macro variable after it is created.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jun 2021 21:56:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-06-23T21:56:28Z</dc:date>
    <item>
      <title>Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/749966#M235798</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So I currently have a table(say, table1) with values like this,&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 40%;" border="1" width="40%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;column_1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;ABC;TOP&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;GEM;POT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;YUS&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;YRS&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I tried to push these values into a macro using this statement,&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc sql noprint;
select column_1
into: macro_1
from table1;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;However, when I tried running %put &amp;amp;macro_1; I get the following error:&lt;/P&gt;
&lt;DIV id="sasLogError1_1624474914042" class="sasError"&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;&lt;BR /&gt;I tried masking both column_1 and macro_1 with %str() but none of them worked. Could someone help me out with this? Thanks in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/749966#M235798</guid>
      <dc:creator>sam_sas2</dc:creator>
      <dc:date>2021-06-23T19:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/749969#M235801</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %quote(&amp;amp;macro_1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/749969#M235801</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-23T19:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750020#M235840</link>
      <description>&lt;P&gt;The error is due to presence of semicolon(;) within the variable value.&lt;BR /&gt;It will work if the semi colon is replaced.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750020#M235840</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-23T20:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750044#M235849</link>
      <description>&lt;P&gt;Not the most useful macro variable I've seen. If you only want one value (from the first record only as the current sql is written) it would be just as easy to do manually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s suggestion works for code as written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you intend to put more of the values into that macro variable you will want to seriously consider whether a semicolon is appropriate at all as you may be jumping through multiple hoops to use it. Other problems result when using commas for separating values.&lt;/P&gt;
&lt;P&gt;It might help to show exactly how you expect to use that macro variable after it is created.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 21:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750044#M235849</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-23T21:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750157#M235894</link>
      <description>Hi, &lt;BR /&gt;Sorry. But I forgot to add - &amp;lt;seperated by '|' &amp;gt; in the above code. &lt;BR /&gt;The purpose is to run a SIMILAR TO ('%(ABC|XYZ|QWE)%') in red shift. &lt;BR /&gt;The values for the SIMILAR TO are present in a table, and I felt this could be a faster way to create macro variable that holds the value in the format- '%(ABC|XYZ|QWE)%'</description>
      <pubDate>Thu, 24 Jun 2021 11:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750157#M235894</guid>
      <dc:creator>sam_sas2</dc:creator>
      <dc:date>2021-06-24T11:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750172#M235895</link>
      <description>&lt;P&gt;How are you planning to use the value in your real application?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need that exact text in the macro variable then the easiest way to be sure the contents are macro quoted is to use %SUPERQ().&lt;/P&gt;
&lt;PRE&gt;493   %let macro1=%superq(macro1);
494   %put &amp;amp;=macro1;
MACRO1=ABC;TOP
&lt;/PRE&gt;
&lt;P&gt;If you are planning to use the value as a string literal later then just add the actual quotes around the value when generating the macro variable.&amp;nbsp; Use single quotes if the values can include macro triggers &amp;amp; and %.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select quote(trim(column_1),"'")
  into :macro_1
  from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 12:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750172#M235895</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-24T12:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750243#M235936</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327668"&gt;@sam_sas2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi, &lt;BR /&gt;Sorry. But I forgot to add - &amp;lt;seperated by '|' &amp;gt; in the above code. &lt;BR /&gt;The purpose is to run a SIMILAR TO ('%(ABC|XYZ|QWE)%') in red shift. &lt;BR /&gt;The values for the SIMILAR TO are present in a table, and I felt this could be a faster way to create macro variable that holds the value in the format- '%(ABC|XYZ|QWE)%'&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That looks like you do not actually want the semicolons that are in your values. I would suggest using the Translate function to replace the ; with a | character.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input var $;
datalines4;
abc;pdq
zzx;ghq
rtv
;;;;

proc sql noprint;
   select translate(var,'|',';') into :macrovar separated by '|'
   from junk
   ;
run;

%put &amp;amp;macrovar.;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jun 2021 15:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750243#M235936</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-24T15:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750270#M235951</link>
      <description>Hi Tom, &lt;BR /&gt;Thanks for the %superq func. &lt;BR /&gt;Also, I couldn't quite get what you meant by 'can include macro triggers &amp;amp; and %.'</description>
      <pubDate>Thu, 24 Jun 2021 17:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750270#M235951</guid>
      <dc:creator>sam_sas2</dc:creator>
      <dc:date>2021-06-24T17:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750373#M236023</link>
      <description>&lt;P&gt;The macro processor ignores text in strings that are bounded by single quotes, but processes text that is bounded by double quotes.&amp;nbsp; So if the string has an &amp;amp; then the macro processor might think&amp;nbsp; you are trying to reference a macro variable. Or if it has a % it might think you are trying to invoke a macro or macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input company $20.;
cards;
A&amp;amp;W
;

proc sql noprint;
select quote(trim(company))
  into :company1 trimmed 
  from have
;
quit;

%put &amp;amp;=company1;

proc sql noprint;
select quote(trim(company),"'") 
  into :company2 trimmed 
  from have
;
quit;

%put &amp;amp;=company2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;24   proc sql noprint;
25   select quote(trim(company))
26     into :company1 trimmed
27     from have
28   ;
29   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


WARNING: Apparent symbolic reference W not resolved.
30
31   %put &amp;amp;=company1;
COMPANY1="A&amp;amp;W"
32
33   proc sql noprint;
34   select quote(trim(company),"'")
35     into :company2 trimmed
36     from have
37   ;
38   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


39
40   %put &amp;amp;=company2;
COMPANY2='A&amp;amp;W'
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 03:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750373#M236023</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-25T03:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to create a macro variable with ";" in the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750374#M236024</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327668"&gt;@sam_sas2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi, &lt;BR /&gt;Sorry. But I forgot to add - &amp;lt;seperated by '|' &amp;gt; in the above code. &lt;BR /&gt;The purpose is to run a SIMILAR TO ('%(ABC|XYZ|QWE)%') in red shift. &lt;BR /&gt;The values for the SIMILAR TO are present in a table, and I felt this could be a faster way to create macro variable that holds the value in the format- '%(ABC|XYZ|QWE)%'&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So if you have those 3 strings in 3 observations in a dataset. You can use SQL to build the middle of the string and then use %BQUOTE() to wrap in the other characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list;
  input term $20.;
cards4;
ABC
XYZ
QWE
;;;;

proc sql noprint;
select term into :list separated by '|' from list;
quit;

%let list=%bquote('%(&amp;amp;list)%') ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that string in your pass through code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to redshift ..... ;
select * from connection to redshift 
(
 select * from X where Y SIMILAR TO (&amp;amp;list)
);
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jun 2021 04:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SQL-to-create-a-macro-variable-with-quot-quot-in-the/m-p/750374#M236024</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-25T04:08:47Z</dc:date>
    </item>
  </channel>
</rss>

