<?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: Create a concatenated string based on multiple observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398794#M96501</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input ID  $          StringID $;
datalines;
0001        ZB012
0001        XC045
0001        CV456
0001        
0002        AS345
0002         
0002        DE458
0003        RT784
0004        SD789
0004        PI066
0005           
0006        TT545
0006        DS410
;
run;
data want;
 length want $ 200;
 do until(last.id);
  set have;
  by id;
  want=catx(',',want,StringID);
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Sep 2017 13:35:23 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-09-26T13:35:23Z</dc:date>
    <item>
      <title>Create a concatenated string based on multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398546#M96425</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I would like to create a string variable that concactenates a variable from a multi-observation database into a longer string (left to right) then outputs this to a&amp;nbsp;seperate single observation database. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;StringID&lt;/P&gt;
&lt;P&gt;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZB012&lt;/P&gt;
&lt;P&gt;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XC045&lt;/P&gt;
&lt;P&gt;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CV456&lt;/P&gt;
&lt;P&gt;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AS345&lt;/P&gt;
&lt;P&gt;0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DE458&lt;/P&gt;
&lt;P&gt;0003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RT784&lt;/P&gt;
&lt;P&gt;0004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SD789&lt;/P&gt;
&lt;P&gt;0004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PI066&lt;/P&gt;
&lt;P&gt;0005&lt;/P&gt;
&lt;P&gt;0006 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TT545&lt;/P&gt;
&lt;P&gt;0006 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DS410&lt;/P&gt;
&lt;P&gt;etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output database:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;longStringID&lt;/P&gt;
&lt;P&gt;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;ZB012,&amp;nbsp;XC045,&amp;nbsp;CV456&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AS345,&amp;nbsp;DE458&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RT784&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SD789,&amp;nbsp;PI066&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0005&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0006 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TT545,&amp;nbsp;DS410&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: The ID with missing String ID should have an output observation. Thanks community.&lt;/P&gt;
&lt;P&gt;I'm using SAS 9.4&lt;/P&gt;
&lt;P&gt;--Tim&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 14:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398546#M96425</guid>
      <dc:creator>tallkell</dc:creator>
      <dc:date>2017-09-25T14:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a concatenated string based on multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398554#M96429</link>
      <description>&lt;P&gt;Do you know the maximum length possible for all combined strings for a given ID? The example below assumes a maximum of 100 characters. If you do not assign a length to longstringid the catx function will default to 200. If you need more than 200 definitely set a length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines missover;
input ID  $          StringID $;
datalines;
0001        ZB012
0001        XC045
0001        CV456
0001        
0002        AS345
0002         
0002        DE458
0003        RT784
0004        SD789
0004        PI066
0005           
0006        TT545
0006        DS410
;
run;

data want;
   set have;
   by id;
   length longstringid $ 100.;
   retain longstringid ;
   if first.id then call missing(longstringid);
   if not missing(stringId) then longstringid =catx(', ',longstringid,stringid);
   if last.id;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 14:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398554#M96429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-25T14:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a concatenated string based on multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398794#M96501</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input ID  $          StringID $;
datalines;
0001        ZB012
0001        XC045
0001        CV456
0001        
0002        AS345
0002         
0002        DE458
0003        RT784
0004        SD789
0004        PI066
0005           
0006        TT545
0006        DS410
;
run;
data want;
 length want $ 200;
 do until(last.id);
  set have;
  by id;
  want=catx(',',want,StringID);
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2017 13:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/398794#M96501</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-26T13:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a concatenated string based on multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/399451#M96752</link>
      <description>&lt;P&gt;Ksharp,&lt;/P&gt;&lt;P&gt;In cases like this (repeatedly adding to the same string) you will get better performance&amp;nbsp;by using CALL CATX than from using the CATX function:&lt;/P&gt;&lt;PRE&gt;data want;
 length want $ 200;
 do until(last.id);
  set have;
  by id;
  call catx(',',want,StringID);
 end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2017 10:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-concatenated-string-based-on-multiple-observations/m-p/399451#M96752</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-09-28T10:54:30Z</dc:date>
    </item>
  </channel>
</rss>

