<?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 add single quotes and commas to a list of words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437511#M108952</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In the first record of a dataset there is a variable&amp;nbsp;with several words separated by space. eg. like this: John James Will Bob&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't know the number of words in the variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to load in a macro variable the string:&amp;nbsp; '&lt;SPAN&gt;John','James','Will','Bob'&amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the macro variable is to be used in a following step in a where statement like this:&amp;nbsp; where name not in (&amp;amp;listnames) .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help is appreciated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks very much in advance&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2018 11:33:18 GMT</pubDate>
    <dc:creator>ciro</dc:creator>
    <dc:date>2018-02-15T11:33:18Z</dc:date>
    <item>
      <title>add single quotes and commas to a list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437511#M108952</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In the first record of a dataset there is a variable&amp;nbsp;with several words separated by space. eg. like this: John James Will Bob&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't know the number of words in the variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to load in a macro variable the string:&amp;nbsp; '&lt;SPAN&gt;John','James','Will','Bob'&amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the macro variable is to be used in a following step in a where statement like this:&amp;nbsp; where name not in (&amp;amp;listnames) .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help is appreciated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks very much in advance&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437511#M108952</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2018-02-15T11:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: add single quotes and commas to a list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437514#M108954</link>
      <description>&lt;P&gt;Just don't.&amp;nbsp; A far simpler more robust method is to use Base SAS:&lt;/P&gt;
&lt;PRE&gt;/* This creates a dataset with all the distinct values from the one string */
data list (keep=word);
  set your_data;
  length word $200;
  do i=1 to countw(str,' ');
      word=scan(str,i,' ');
     output;
  end;
run;
proc sort data=list nodupkey;
  by word;
run;

/* Now we use the list in a where clause */
proc sql;
  create table want as
  select  *
  from    have
  where name not in (select word from list);
quit;&lt;/PRE&gt;
&lt;P&gt;This will expand and decrease as needed for the data items, and requires far less messy code.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437514#M108954</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T11:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: add single quotes and commas to a list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437525#M108958</link>
      <description>&lt;P&gt;this works (Assuming there is no gap in between a single name like de Morgan)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input names:$200.;
datalines;
John James Will Bob PK SK DK Simon
;
run;


data _null_;
set have;
if _n_=1 then do;
names1="'"||tranwrd(trim(names), " ", "','")||"'";
call symput('names',names1);
end;
run;

%put &amp;amp;names.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437525#M108958</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-15T11:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: add single quotes and commas to a list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437654#M109021</link>
      <description>&lt;P&gt;Note that creating a macro variable of this type means that unless you take extra steps you cannot pass it as a parameter value in a macro, use certain functions such as %scan or %substr&amp;nbsp;with it and get expected results.&lt;/P&gt;
&lt;P&gt;Note that for your stated use the COMMA is not needed and is what complicates passing as a parameter or use with %scan and %substr&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-single-quotes-and-commas-to-a-list-of-words/m-p/437654#M109021</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-15T15:55:02Z</dc:date>
    </item>
  </channel>
</rss>

