<?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: Combining the strings of unique items through a Data Step into one string per ID? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475829#M286003</link>
    <description>&lt;P&gt;If you have really big data and want only one pass with the data, the data step is a faster option. Or if you're calculating multiple things in the same data step you may want that approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219392"&gt;@PSL&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the answer, could you explain the difference between the two solutions? Would there be any reason to choose the Data Step over the Proc SQL or vice versa?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jul 2018 21:00:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-05T21:00:09Z</dc:date>
    <item>
      <title>Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475517#M285998</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the below list to show with each ID only once with all&amp;nbsp;multiple rows of strings combined&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;code&lt;/TD&gt;&lt;TD&gt;string&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;h&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;i&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;k&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;l&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;m&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using to get the initial data is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data work.blah;  
   infile datalines missover; 
   input ID $ string $;  
   datalines; 
1 a
1 b
2 e
3 g
3 h
4 i
5 k
5 l
5 m
;                         &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;code&lt;/TD&gt;&lt;TD&gt;list&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;a, b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;g, h&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;i&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;k, l, m&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am using is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data strings;&lt;BR /&gt; length list $100.;&lt;BR /&gt; set work.blah end=eof;&lt;BR /&gt; retain list;&lt;BR /&gt; if n=1 then list=string;&lt;BR /&gt; else list = cats(list,", ",string);&lt;BR /&gt; if eof then output;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately the result I am getting is&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;list&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;string&lt;/TD&gt;&lt;TD&gt;n&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;,a,b,e,g,h,i,k,l,m&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;m&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;P&gt;1) How can I get the unique IDs, and not just the last one (5)&lt;/P&gt;&lt;P&gt;2) How can I get the first string to start and not the ", "&lt;/P&gt;&lt;P&gt;3) How can I drop the 'string' and 'n' columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference I am using SAS EG 6.1 M1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 03:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475517#M285998</guid>
      <dc:creator>PSL</dc:creator>
      <dc:date>2018-07-05T03:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475518#M285999</link>
      <description>&lt;P&gt;There’s two methods here with a fully worked example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 04:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475518#M285999</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-05T04:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475519#M286000</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.blah;  
   infile datalines missover; 
   input ID $ string $;  
   datalines; 
1 a
1 b
2 e
3 g
3 h
4 i
5 k
5 l
5 m
;   

data want;
set blah;
by id;
length list $50;
retain list ;
if first.id then list=string;
else list=catx(',',list,string);
if last.id;
drop string;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 04:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475519#M286000</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-05T04:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475820#M286001</link>
      <description>Thanks for the answer, could you explain the difference between the two solutions? Would there be any reason to choose the Data Step over the Proc SQL or vice versa?</description>
      <pubDate>Thu, 05 Jul 2018 20:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475820#M286001</guid>
      <dc:creator>PSL</dc:creator>
      <dc:date>2018-07-05T20:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475828#M286002</link>
      <description>&lt;P&gt;Thanks, that worked perfect&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 20:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475828#M286002</guid>
      <dc:creator>PSL</dc:creator>
      <dc:date>2018-07-05T20:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475829#M286003</link>
      <description>&lt;P&gt;If you have really big data and want only one pass with the data, the data step is a faster option. Or if you're calculating multiple things in the same data step you may want that approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219392"&gt;@PSL&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the answer, could you explain the difference between the two solutions? Would there be any reason to choose the Data Step over the Proc SQL or vice versa?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 21:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475829#M286003</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-05T21:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the strings of unique items through a Data Step into one string per ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475830#M286004</link>
      <description>Understood, thank you very much</description>
      <pubDate>Thu, 05 Jul 2018 21:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-the-strings-of-unique-items-through-a-Data-Step-into/m-p/475830#M286004</guid>
      <dc:creator>PSL</dc:creator>
      <dc:date>2018-07-05T21:00:48Z</dc:date>
    </item>
  </channel>
</rss>

