<?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: IN operator - macro variable - characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422825#M103960</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85578"&gt;@Alain38&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your help but it provides a syntax error: "NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.&amp;nbsp; Inserting white space between a quoted string and the succeeding identifier is recommended."&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is &lt;STRONG&gt;not&lt;/STRONG&gt; an error, it is &lt;STRONG&gt;NOTE.&lt;/STRONG&gt; There are a number of syntax elements that have special meanings when the value is quoted and followed immediately by a character: '01JAN2017'd&amp;nbsp; (the 'd indicates the quoted element should be treated as a date), "07:01:23"t (the quoted element should be treated as a time, "stupid varname"n (the quoted value is a variable name which may not follow typical SAS variable name rules), ' 'dt would be treated as a datetime. So when you use any thing that is quoted followed by a character without a space you get the resulting &lt;STRONG&gt;NOTE&lt;/STRONG&gt; as a warning that in the future the code may behave differently.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2017 18:36:29 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-12-20T18:36:29Z</dc:date>
    <item>
      <title>IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422809#M103952</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I retrieve a list of ID codes in a macro variable as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select distinct ID_code into : ID_list separated by ',' from Work.List;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and use it with a IN operator, inside a WHERE clause as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Work.Sample2;
	set Work.Sample (where=(ID_code in (&amp;amp;ID_list)));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;it only works if the ID_codes are numeric. When they are characters I get the following error "WHERE clause operator requires compatible variables" so I guess that some quotation marks are required but I don't know how to write it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help,&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 17:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422809#M103952</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2017-12-20T17:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422811#M103953</link>
      <description>&lt;P&gt;For characters you need quotes around them:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt; noprint;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;  select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;distinct&lt;/SPAN&gt; ID_code &lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; : ID_list separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'","'&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; Work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;List&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the double quotes.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422811#M103953</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-20T18:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422815#M103954</link>
      <description>&lt;P&gt;Thank you very much for your help but it provides a syntax error: "NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.&amp;nbsp; Inserting white space between a quoted string and the succeeding identifier is recommended."&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422815#M103954</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2017-12-20T18:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422816#M103955</link>
      <description>&lt;P&gt;Please post the code used and the log as I have no way of guessing what you ran.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422816#M103955</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-20T18:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422818#M103956</link>
      <description>&lt;P&gt;&lt;BR /&gt;data w;&lt;BR /&gt;input x $;&lt;BR /&gt;datalines;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct &lt;EM&gt;&lt;STRONG&gt;quote(trim(x)) into : ID_list&lt;/STRONG&gt;&lt;/EM&gt; separated by ',' from Work.w;&lt;BR /&gt;quit;&lt;BR /&gt;data w1;&lt;BR /&gt;input x $;&lt;BR /&gt;datalines;&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;;&lt;BR /&gt;data Work.Sample2;&lt;BR /&gt;set Work.w1 (where=(x in (&amp;amp;ID_list)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422818#M103956</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-20T18:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422823#M103958</link>
      <description>&lt;P&gt;The solution from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;is viable, but the macro variable doesn't contain beginning and final quotes.&amp;nbsp; You will need to change your subsequent code to match:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; Work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Sample2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; Work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Sample &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ID_code &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;("&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;ID_list"&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422823#M103958</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-20T18:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422824#M103959</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;Your solution is working, thank you so much!&lt;/P&gt;&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; for this clarification, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; code is working as well this way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422824#M103959</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2017-12-20T18:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422825#M103960</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85578"&gt;@Alain38&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your help but it provides a syntax error: "NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.&amp;nbsp; Inserting white space between a quoted string and the succeeding identifier is recommended."&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is &lt;STRONG&gt;not&lt;/STRONG&gt; an error, it is &lt;STRONG&gt;NOTE.&lt;/STRONG&gt; There are a number of syntax elements that have special meanings when the value is quoted and followed immediately by a character: '01JAN2017'd&amp;nbsp; (the 'd indicates the quoted element should be treated as a date), "07:01:23"t (the quoted element should be treated as a time, "stupid varname"n (the quoted value is a variable name which may not follow typical SAS variable name rules), ' 'dt would be treated as a datetime. So when you use any thing that is quoted followed by a character without a space you get the resulting &lt;STRONG&gt;NOTE&lt;/STRONG&gt; as a warning that in the future the code may behave differently.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422825#M103960</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-20T18:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422826#M103961</link>
      <description>&lt;P&gt;For character strings you need to quote the values so that they look like string literals. You can use the QUOTE() function and avoid problems that would be caused by embedded quote characters in the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(ID_code)) into :ID_list separated by ',' from Work.List;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your values might contain macro triggers (&amp;amp; or %) then using single quote for the quoting character instead of double quote will prevent the macro processor from trying to evaluate them when you expand the macro value.&amp;nbsp; Also note that SAS will happily allow space delimited lists instead of comma delimited lists in the IN () operator. This will make your macro variable easier to work with in other ways such as passing it into macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(ID_code),"'") into :ID_list separated by ' ' from Work.List;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422826#M103961</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-20T18:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422827#M103962</link>
      <description>&lt;P&gt;Thank you all for answering me so quickly and for your explanations&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/422827#M103962</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2017-12-20T18:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: IN operator - macro variable - characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/423084#M104025</link>
      <description>&lt;P&gt;Or use SYMGET() and you don't need care about if it is numeric or character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct age into : list separated by ',' from sashelp.class;
quit;

data want;
 set sashelp.class;
 if findw(symget('list'),strip(age),',');
run;







proc sql noprint;
select distinct name into : list separated by ',' from sashelp.class;
quit;

data want;
 set sashelp.class;
 if findw(symget('list'),strip(name),',');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 13:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IN-operator-macro-variable-characters/m-p/423084#M104025</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-21T13:20:48Z</dc:date>
    </item>
  </channel>
</rss>

