<?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: change a space delimited list into a comma delimited list with each element enclosed by quotatio in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731151#M227758</link>
    <description>&lt;P&gt;Change your select statement to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from names where name in (%upcase(%sysfunc(tranwrd("&amp;amp;name",%str( ),%str(",")))));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Sat, 03 Apr 2021 15:46:21 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-04-03T15:46:21Z</dc:date>
    <item>
      <title>change a space delimited list into a comma delimited list with each element enclosed by quotation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731148#M227756</link>
      <description>&lt;P&gt;I am writing a macro that takes in a list and selects records from a dataset with those names. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will look something like this (it has to be done in a macro with a proc sql so I can't do this in a data step):&lt;/P&gt;&lt;P&gt;%macro test (name = John Jake Mary);&lt;/P&gt;&lt;P&gt;proc sql;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select * from names where name in&amp;nbsp;&lt;SPAN&gt;(&lt;/SPAN&gt;%upcase&lt;SPAN&gt;(&lt;/SPAN&gt;%sysfunc&lt;SPAN&gt;(tranwrd(&lt;/SPAN&gt;&lt;SPAN&gt;"&amp;amp;name"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;%str&lt;SPAN&gt;( ),&lt;/SPAN&gt;%str&lt;SPAN&gt;(,)))));&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Right now, all it is doing is just outputting this "John, Jake, Mary" but I want there to be quotations around each element in the list. &amp;nbsp;so the output looks like&amp;nbsp;this "John", "Jake", "Mary"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731148#M227756</guid>
      <dc:creator>gleebglorb</dc:creator>
      <dc:date>2021-04-03T15:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: change a space delimited list into a comma delimited list with each element enclosed by quotatio</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731151#M227758</link>
      <description>&lt;P&gt;Change your select statement to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from names where name in (%upcase(%sysfunc(tranwrd("&amp;amp;name",%str( ),%str(",")))));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731151#M227758</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-03T15:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: change a space delimited list into a comma delimited list with each element enclosed by quotatio</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731154#M227760</link>
      <description>&lt;P&gt;Because you didn't ask it to insert the quotes into the middle.&amp;nbsp; Don't just change the spaces to commas. Change them to commas with quotes around them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where name in (%sysfunc(tranwrd(%upcase("&amp;amp;name"),%str( ),",")))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might also want to use single quotes instead, especially is you might be pushing this code into some remote database where only single quotes are used for string literals.&lt;/P&gt;
&lt;P&gt;Also watch out for extra spaces, you might want to use COMPBL() to collapse them to single spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(name);
%let name=%sysfunc(compbl(&amp;amp;name));
proc sql; 
select * from names 
  where name in (%sysfunc(tranwrd(%upcase(%str(%')&amp;amp;name%str(%')),%str( ),',')))
;
quit;
%mend;

%test(name = John Jake Mary);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Apr 2021 15:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731154#M227760</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-03T15:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: change a space delimited list into a comma delimited list with each element enclosed by quotatio</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731224#M227783</link>
      <description>&lt;PRE&gt;%macro test(name=);

proc sql; 
select * from sashelp.class where findw(symget('name'),strip(name),' ','i'); 
quit;

%mend;

%test(name = Janet Mary John)&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Apr 2021 12:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-a-space-delimited-list-into-a-comma-delimited-list-with/m-p/731224#M227783</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-04T12:17:16Z</dc:date>
    </item>
  </channel>
</rss>

