<?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 Character macro variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480846#M286672</link>
    <description>&lt;P&gt;So you need quotes around string literals. So either add the quotes when making the macro variable.&amp;nbsp; You can use the QUOTE() function in your SQL query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a common enough problem to convert a space delimited list of words into a list of quoted words that there are many macros available to make the conversion.&amp;nbsp; For example:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_self"&gt;%qlist&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for simple list with just a single space between the words you can do it with a simple call to TRANWRD() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset;
  set stats;
  where subs in ("%sysfunc(tranwrd(&amp;amp;List_subs,%str( )," "))");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You can clean up a user entered list that might have multiple spaces between the words by using the COMPBL() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let qlist=%sysfunc(compbl(&amp;amp;list_subs));
%let qlist="%sysfunc(tranwrd(&amp;amp;qlist,%str( )," "))";

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Jul 2018 16:28:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-24T16:28:09Z</dc:date>
    <item>
      <title>Using a Character macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480840#M286669</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have just run into a problem with macro variable lists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2&amp;nbsp;data sets:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 229px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21971i5119B3E6B8065EFE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.PNG" style="width: 419px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21972i99134DB4E4700585/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;created with the following codes respectively:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Subidiaries;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length subs $25;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input Subs $;&lt;BR /&gt;cards;&lt;BR /&gt;Walmart&lt;BR /&gt;Sainsbury&lt;BR /&gt;Argos&lt;BR /&gt;Holland&lt;BR /&gt;PureGym&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data stats;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length subs $25 Customer_count 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input subs $ customer_count;&lt;BR /&gt;cards;&lt;BR /&gt;Walmart 33&lt;BR /&gt;Argos 55&lt;BR /&gt;Pimps 66&lt;BR /&gt;Lugos 67&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I create a macro variable list from the first table above&amp;nbsp;use in&amp;nbsp;filtering on&amp;nbsp;the second table. The queries used are:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select subs&lt;BR /&gt;into :List_subs separated by ' '&lt;BR /&gt;from Subidiaries;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data subset;&lt;BR /&gt;&amp;nbsp; set stats;&lt;BR /&gt;&amp;nbsp; where subs in (&amp;amp;List_subs);&lt;BR /&gt;&amp;nbsp;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I get the below error in the log. Can anyone advice me on how to resolve this?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture3.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21973i50C3949850ED3DC1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture3.PNG" alt="Capture3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 15:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480840#M286669</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T15:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Character macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480841#M286670</link>
      <description>&lt;P&gt;correction:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select&lt;STRONG&gt; quote(trim(subs))&lt;/STRONG&gt;&lt;BR /&gt;into :List_subs separated by ' '&lt;BR /&gt;from Subidiaries;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data subset;&lt;BR /&gt;set stats;&lt;BR /&gt;where subs in (&amp;amp;List_subs);&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 15:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480841#M286670</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-24T15:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Character macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480842#M286671</link>
      <description>&lt;P&gt;The data step IN wants to see quotes around each individual value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;in ('Walmart' 'Sainsbury' )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
select subs
into :List_subs separated by ' '
from Subidiaries;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
select quote( strip(subs))
into :List_subs separated by ' '
from Subidiaries;
quit;&lt;/PRE&gt;
&lt;P&gt;to place quotes around each value. The strip may be needed to preven having spaces depending on the actual values and declared length of the variable SUBS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using that list elsewhere where you do not want the quotes you'll need to build to separate list variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 17:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480842#M286671</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-05T17:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Character macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480846#M286672</link>
      <description>&lt;P&gt;So you need quotes around string literals. So either add the quotes when making the macro variable.&amp;nbsp; You can use the QUOTE() function in your SQL query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a common enough problem to convert a space delimited list of words into a list of quoted words that there are many macros available to make the conversion.&amp;nbsp; For example:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_self"&gt;%qlist&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for simple list with just a single space between the words you can do it with a simple call to TRANWRD() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset;
  set stats;
  where subs in ("%sysfunc(tranwrd(&amp;amp;List_subs,%str( )," "))");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You can clean up a user entered list that might have multiple spaces between the words by using the COMPBL() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let qlist=%sysfunc(compbl(&amp;amp;list_subs));
%let qlist="%sysfunc(tranwrd(&amp;amp;qlist,%str( )," "))";

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 16:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Character-macro-variable-list/m-p/480846#M286672</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-24T16:28:09Z</dc:date>
    </item>
  </channel>
</rss>

