<?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: Put list elements into parentheses in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837594#M331195</link>
    <description>Thank you, all! This worked!&lt;BR /&gt;Best wishes.</description>
    <pubDate>Mon, 10 Oct 2022 03:03:05 GMT</pubDate>
    <dc:creator>pink_poodle</dc:creator>
    <dc:date>2022-10-10T03:03:05Z</dc:date>
    <item>
      <title>Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837045#M330978</link>
      <description>&lt;P&gt;I have a list, for example a, b, c. It can be put into a variable with values a, b, c.&lt;/P&gt;
&lt;P&gt;I would like to make it into [a], [b], [c].&lt;/P&gt;
&lt;P&gt;Strangely,&amp;nbsp;catx('[ ', variable, ']') produces values "[] a", "[] b", "[]c". Why?&lt;/P&gt;
&lt;P&gt;Any suggestions are welcome.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 21:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837045#M330978</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-05T21:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837046#M330979</link>
      <description>I think you want CATT not CATX().&lt;BR /&gt;X specifies a delimiter between each term, which is the first parameter.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Oct 2022 21:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837046#M330979</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-05T21:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837049#M330980</link>
      <description>&lt;P&gt;I'm a little confused. Is this in a DATA step with one variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  list='a, b, c';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is this a macro setting where you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list= a, b, c ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In either way, SAS doesn't know it's a list, but you can for example iterate over the items to update the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can approach it as text replacement, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  list='a, b, c';
  want=cats('[',transtrn(list,', ','], ['),']') ;
  put list= ;
  put want= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2022 21:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837049#M330980</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-10-05T21:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837051#M330981</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235176"&gt;@pink_poodle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a list, for example a, b, c. It can be put into a variable with values a, b, c.&lt;/P&gt;
&lt;P&gt;I would like to make it into [a], [b], [c].&lt;/P&gt;
&lt;P&gt;Strangely,&amp;nbsp;catx('[ ', variable, ']') produces values "[] a", "[] b", "[]c". Why?&lt;/P&gt;
&lt;P&gt;Any suggestions are welcome.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would have to show a complete data step and possibly some data as I don't actually your believe your output claim given the little bit of sort of code that you show.&lt;/P&gt;
&lt;PRE&gt;77   data example;
78      variable='a';
79      newvar = catx('[',variable,']');
80      put newvar=;
81   run;

newvar=a[]
&lt;/PRE&gt;
&lt;P&gt;so the [] would appear &lt;STRONG&gt;after&lt;/STRONG&gt; the value of variable with a [ preceding the next value&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 21:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837051#M330981</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-05T21:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837077#M330984</link>
      <description>&lt;P&gt;Yes, thank you! I want the output to be something like &amp;nbsp;‘[a]’. Instead, it is ‘a[ ]’.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 00:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837077#M330984</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-06T00:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837086#M330987</link>
      <description>&lt;P&gt;Data.&lt;/P&gt;
&lt;P&gt;Example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basic for one &lt;STRONG&gt;value&lt;/STRONG&gt; would be something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; newvar = cats('[',variable,']');&lt;/P&gt;
&lt;P&gt;but you keep saying "list". So we need to see what you currently have. So far it is not clear if you have one variable, 3 or more variables, or whatever. Plus we can't tell if there are multiple values in a single variable that need to be torn apart and reassembled.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 01:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837086#M330987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-06T01:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837102#M330992</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  list = 'a, b, c';
  attrib list_new length = $ 200;
  do i = 1 to countw(list,',');
    list_new = catx(', ', list_new, cats('[', scan(list,i), ']'));
  end;
  put _all_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Oct 2022 02:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837102#M330992</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-10-06T02:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837103#M330993</link>
      <description>&lt;P&gt;How do you have the list?&amp;nbsp; Is it in a dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input variable $ ;
cards;
a
b
c
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do you want the result?&amp;nbsp; Do you want it in a dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have end=eof;
  length list $100 ;
  list=catx(',',list,cats('[',variable,']'));
  retain list;
  if eof;
  keep list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And why did you ask about&amp;nbsp;parentheses () if you want to use square brackets [] instead?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 03:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837103#M330993</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-06T03:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Put list elements into parentheses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837594#M331195</link>
      <description>Thank you, all! This worked!&lt;BR /&gt;Best wishes.</description>
      <pubDate>Mon, 10 Oct 2022 03:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-list-elements-into-parentheses/m-p/837594#M331195</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-10T03:03:05Z</dc:date>
    </item>
  </channel>
</rss>

