<?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: read macro variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762832#M241563</link>
    <description>&lt;P&gt;But if you insist on using a macro-variable, you have two options:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Fix the step creating the list, so that every value is quoted, so that it can be used in a data step like the one you have posted, just don't quote &amp;amp;color there.&lt;/LI&gt;
&lt;LI&gt;Follow &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; suggestion using the function indexw, but replace the list of colors with "&amp;amp;Color".&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when debugging code with macro-variables is recommended.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 12:59:46 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-08-20T12:59:46Z</dc:date>
    <item>
      <title>read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762811#M241554</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a list with space in a macro variable. How can i read this to check if i have the same values in the other list.&lt;/P&gt;&lt;P&gt;eg: %let color =&amp;nbsp; red green yellow blue;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data col;&lt;/P&gt;&lt;P&gt;set brown;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;if col in ('&amp;amp;color') then output;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 11:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762811#M241554</guid>
      <dc:creator>Stephenjohn</dc:creator>
      <dc:date>2021-08-20T11:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762814#M241557</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393492"&gt;@Stephenjohn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a list with space in a macro variable. How can i read this to check if i have the same values in the other list.&lt;/P&gt;
&lt;P&gt;eg: %let color =&amp;nbsp; red green yellow blue;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data col;&lt;/P&gt;
&lt;P&gt;set brown;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;if col in ('&amp;amp;color') then output;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Macro variables when representing a value need to be enclosed in double quotes. When you place the macro variable inside single quotes, like you have with '&amp;amp;color' then the macro variable does not resolve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you should write a bit of code that execute properly before using any macro variables. Then show us that code so we can show how to properly use a macro variable.&lt;/P&gt;
&lt;P&gt;When the macro variable is enclosed in a set of quotes you likely wont get what you want but need to see what values you are actually using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this for a quick example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
   col = 'red';
   if col in ('red green yellow blue') then output;
run;&lt;/PRE&gt;
&lt;P&gt;Do you expect the single value of COL to be output to the data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test the code.&lt;/P&gt;
&lt;P&gt;Then consider what goes on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suspect that you need to consider just how you are making your macro variable as your current one won't work in the IN comparison.&lt;/P&gt;
&lt;P&gt;To have a valid IN comparison looking for any of those words you would need&lt;/P&gt;
&lt;PRE&gt;data test;
   col = 'red';
   if col in ('red' 'green' 'yellow' 'blue') then output;
run;&lt;/PRE&gt;
&lt;P&gt;However consider a different way to search for a string as part of a single string:&lt;/P&gt;
&lt;PRE&gt;data test;
   col = 'red';
   if Indexw('red green yellow blue',col)&amp;gt;0 then output;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 11:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762814#M241557</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-20T11:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762817#M241559</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that was just an example.&amp;nbsp; i have a huge list of values into a macro variable.. Is there any way i can do this for a IN comparison. or compare a variable values with that of the macro variable values.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 11:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762817#M241559</guid>
      <dc:creator>Stephenjohn</dc:creator>
      <dc:date>2021-08-20T11:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762829#M241562</link>
      <description>&lt;P&gt;Step 1: Convert the &amp;amp;color to a dataset, with one value in each observation.&lt;/P&gt;
&lt;P&gt;Step 2: Use normal merge or join to create dataset "col".&lt;/P&gt;
&lt;P&gt;Step 3: Be happy, that the unnecessary usage of macro-variables could be avoided.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 12:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762829#M241562</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-20T12:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762832#M241563</link>
      <description>&lt;P&gt;But if you insist on using a macro-variable, you have two options:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Fix the step creating the list, so that every value is quoted, so that it can be used in a data step like the one you have posted, just don't quote &amp;amp;color there.&lt;/LI&gt;
&lt;LI&gt;Follow &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; suggestion using the function indexw, but replace the list of colors with "&amp;amp;Color".&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when debugging code with macro-variables is recommended.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 12:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762832#M241563</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-20T12:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762858#M241564</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393492"&gt;@Stephenjohn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;that was just an example.&amp;nbsp; i have a huge list of values into a macro variable.. Is there any way i can do this for a IN comparison. or compare a variable values with that of the macro variable values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure why the insistence on IN but your macro variable would have to look like a valid list of values for the IN operator, i.e. every value enclosed in quotes. Typically a "huge of list of values" means that a macro variable is the wrong approach from one of several standpoints.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another possible approach that can test individual values against a list is a custom format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc format;
value $testlist
'abc', 'pdq', 'xyz'="In list"
other='Not in list'
;

data test;
   input col $;
   if put(col,$testlist.)='In list' then output;
datalines;
abc
bbb
bq
pdq
;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Aug 2021 14:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/762858#M241564</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-20T14:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: read macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/763019#M241631</link>
      <description>Data col;&lt;BR /&gt;&lt;BR /&gt;set brown;&lt;BR /&gt;&lt;BR /&gt;if   findw("&amp;amp;color", strip(col) )   then output;&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 21 Aug 2021 10:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-macro-variable-list/m-p/763019#M241631</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-21T10:14:52Z</dc:date>
    </item>
  </channel>
</rss>

