<?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 macro variable for proc sql like condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176252#M264687</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you need triple &amp;amp; if I understand your macro variable structure.&lt;/P&gt;&lt;P&gt;You can use&amp;nbsp; %QUOTE() to generate a protected percent sign so that SAS doesn't think you want to call macro.&lt;/P&gt;&lt;P&gt;Or you can just use the CONTAINS operator instead of the LIKE operator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; i=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; name=value;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; value1=A ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; upcase(name) like &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"%quote(%%)&amp;amp;&amp;amp;&amp;amp;name&amp;amp;i%"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;sqlobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; upcase(name) contains &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"&amp;amp;&amp;amp;&amp;amp;name&amp;amp;i"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;sqlobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Nov 2014 18:38:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-11-18T18:38:47Z</dc:date>
    <item>
      <title>using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176248#M264683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to use a macro variable for proc sql like condition?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Such as :&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; create table key as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select * from c.numkeys&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where upcase(esc) like&amp;nbsp; '%&amp;amp;&amp;amp;&lt;STRONG&gt;name&lt;/STRONG&gt;&amp;amp;&lt;STRONG&gt;i&lt;/STRONG&gt;.%' ; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;name&lt;/STRONG&gt; and &lt;STRONG&gt;i&lt;/STRONG&gt; are macro variables. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 16:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176248#M264683</guid>
      <dc:creator>nov</dc:creator>
      <dc:date>2014-11-18T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176249#M264684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I personally would avoid using several macro variables like that, i.e. &amp;amp;name, and &amp;amp;I.&amp;nbsp; It becomes very messy with all those ampersands and de-referencing.&amp;nbsp; Never actually found a time when I needed to do that. &lt;/P&gt;&lt;P&gt;As for your question, the like would need to have double quotes:&lt;/P&gt;&lt;P&gt;"%&amp;amp;&amp;amp;&lt;STRONG&gt;name&lt;/STRONG&gt;&amp;amp;&lt;STRONG&gt;i&lt;/STRONG&gt;.%"&lt;/P&gt;&lt;P&gt;Otherwise the macro variable won't de-reference.&amp;nbsp; As for &amp;amp;&amp;amp;this and the other...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 16:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176249#M264684</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-18T16:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176250#M264685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The double quotes were used before. The warning messages are:&lt;/P&gt;&lt;P&gt;WARNING: Apparent invocation of macro&amp;nbsp; &lt;STRONG&gt;value1&lt;/STRONG&gt; not resolved.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference NAME not resolved.&lt;/P&gt;&lt;P&gt;WARNING: Apparent invocation of macro &lt;STRONG&gt;value1&lt;/STRONG&gt; not resolved.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference &lt;STRONG&gt;value1value1&lt;/STRONG&gt; not resolved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value1 is name's value. Is it a way to get out the warnings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 16:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176250#M264685</guid>
      <dc:creator>nov</dc:creator>
      <dc:date>2014-11-18T16:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176251#M264686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Exactly, parts of the macro variables are being de-referenced at differing times.&amp;nbsp; TBH I am not going to try to work out which order they do it as I really don't like lines of ampersands.&amp;nbsp; Post some example code and test data/output and will see what I can come up with tomorrow.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 18:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176251#M264686</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-18T18:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176252#M264687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you need triple &amp;amp; if I understand your macro variable structure.&lt;/P&gt;&lt;P&gt;You can use&amp;nbsp; %QUOTE() to generate a protected percent sign so that SAS doesn't think you want to call macro.&lt;/P&gt;&lt;P&gt;Or you can just use the CONTAINS operator instead of the LIKE operator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; i=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; name=value;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; value1=A ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; upcase(name) like &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"%quote(%%)&amp;amp;&amp;amp;&amp;amp;name&amp;amp;i%"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;sqlobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; upcase(name) contains &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"&amp;amp;&amp;amp;&amp;amp;name&amp;amp;i"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;sqlobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 18:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176252#M264687</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-11-18T18:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176253#M264688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not use SYMGET() ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%let value1=A ;
proc sql&amp;nbsp; ;
select * from sashelp.class
where upcase(name) contains symget('value1');
;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Nov 2014 13:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/176253#M264688</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-19T13:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variable for proc sql like condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/359869#M264689</link>
      <description>Thanks so much Xia - this is just what I needed&lt;BR /&gt;- in particular notice the use of the plain variable rather than the variable with $ prefix didn't work inside the proc sql &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 19 May 2017 03:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variable-for-proc-sql-like-condition/m-p/359869#M264689</guid>
      <dc:creator>loweowen</dc:creator>
      <dc:date>2017-05-19T03:24:20Z</dc:date>
    </item>
  </channel>
</rss>

