<?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: Delimited String from Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73793#M15903</link>
    <description>Thanks guys, It appears i was closer then i originally thought.&lt;BR /&gt;
All sorted!</description>
    <pubDate>Wed, 22 Sep 2010 23:25:42 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-09-22T23:25:42Z</dc:date>
    <item>
      <title>Delimited String from Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73789#M15899</link>
      <description>I for the life of me can't figure this out..&lt;BR /&gt;
and i know i'm missing something simple (surely).&lt;BR /&gt;
&lt;BR /&gt;
I've got a dataset along the lines of:&lt;BR /&gt;
&lt;BR /&gt;
Patient_ID                         Result&lt;BR /&gt;
123                                   Z100&lt;BR /&gt;
123                                   A100&lt;BR /&gt;
124                                   B100&lt;BR /&gt;
124                                   Z100&lt;BR /&gt;
127                                   H119&lt;BR /&gt;
127                                   J112&lt;BR /&gt;
127                                   Z100&lt;BR /&gt;
&lt;BR /&gt;
What i want to be able to do is create a data set that contains the following:&lt;BR /&gt;
&lt;BR /&gt;
Patient_ID                          Result&lt;BR /&gt;
123                                    Z100,A100&lt;BR /&gt;
124                                    B100,Z100&lt;BR /&gt;
127                                    H119,J112,Z100&lt;BR /&gt;
&lt;BR /&gt;
I was attempting to use a Data Step but couldn't appear to reference the previously used variable.&lt;BR /&gt;
&lt;BR /&gt;
If it was a numeric value and i was calculating a total then it seems to work, but trying to concatenate strings is making things more difficult.&lt;BR /&gt;
&lt;BR /&gt;
I guess i could transpose the dataset and then concat the resulting columns, but that seems like an overly complicated method</description>
      <pubDate>Wed, 22 Sep 2010 06:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73789#M15899</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T06:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delimited String from Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73790#M15900</link>
      <description>HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data want(drop=Patient_ID);&lt;BR /&gt;
input Patient_ID Result $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
123 Z100&lt;BR /&gt;
123 A100&lt;BR /&gt;
124 B100&lt;BR /&gt;
124 Z100&lt;BR /&gt;
127 H119&lt;BR /&gt;
127 J112&lt;BR /&gt;
127 Z100&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  by Patient_ID;&lt;BR /&gt;
  retain result_arr;&lt;BR /&gt;
  length result_arr $ 1000;&lt;BR /&gt;
&lt;BR /&gt;
  if first.patient_id then&lt;BR /&gt;
    result_arr=result;&lt;BR /&gt;
  else&lt;BR /&gt;
    result_arr=cats(result_arr,',',result);&lt;BR /&gt;
&lt;BR /&gt;
  if last.patient_id then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=want;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 22 Sep 2010 09:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73790#M15900</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-09-22T09:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delimited String from Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73791#M15901</link>
      <description>I agree with Patrick's approach but, as many of us have at some time, he apparently responded before drinking enough coffee!&lt;BR /&gt;
&lt;BR /&gt;
In his example, make sure that the first file is called have, not want and don't drop Patient_ID.&lt;BR /&gt;
&lt;BR /&gt;
Plus, I don't know if IFC is any more efficient than a combination of if then statements, but I prefer it.  E.g.,&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
input Patient_ID Result $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
123 Z100&lt;BR /&gt;
123 A100&lt;BR /&gt;
124 B100&lt;BR /&gt;
124 Z100&lt;BR /&gt;
127 H119&lt;BR /&gt;
127 J112&lt;BR /&gt;
127 Z100&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  by Patient_ID;&lt;BR /&gt;
  retain result_arr;&lt;BR /&gt;
  length result_arr $ 1000;&lt;BR /&gt;
  result_arr=ifc( first.patient_id,result,&lt;BR /&gt;
                  cats(result_arr,',',result));&lt;BR /&gt;
  if last.patient_id then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 22 Sep 2010 12:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73791#M15901</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-22T12:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Delimited String from Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73792#M15902</link>
      <description>...&lt;BR /&gt;
&amp;gt; I guess i could transpose the dataset and then concat&lt;BR /&gt;
&amp;gt; the resulting columns, but that seems like an overly&lt;BR /&gt;
&amp;gt; complicated method&lt;BR /&gt;
...&lt;BR /&gt;
*Overly* complicated? Is it? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
[pre]&lt;BR /&gt;
   /* test data */&lt;BR /&gt;
   data one;&lt;BR /&gt;
     input id code $;&lt;BR /&gt;
   datalines;&lt;BR /&gt;
   123 Z100&lt;BR /&gt;
   123 A100&lt;BR /&gt;
   124 B100&lt;BR /&gt;
   124 Z100&lt;BR /&gt;
   127 H119&lt;BR /&gt;
   127 J112&lt;BR /&gt;
   127 Z100&lt;BR /&gt;
   ;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* one obs per id, codes delimited with a comma and space */&lt;BR /&gt;
   proc transpose data=one out=two;&lt;BR /&gt;
     var code;&lt;BR /&gt;
     by id;&lt;BR /&gt;
   run;&lt;BR /&gt;
   data three;&lt;BR /&gt;
     set two;&lt;BR /&gt;
     length codes $200; /* set long enough length */&lt;BR /&gt;
     codes = catx(", ", of col:);&lt;BR /&gt;
     keep id codes;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* check */&lt;BR /&gt;
   proc print data=three;&lt;BR /&gt;
   run;&lt;BR /&gt;
   /* on lst&lt;BR /&gt;
   Obs     id    codes&lt;BR /&gt;
    1     123    Z100, A100&lt;BR /&gt;
    2     124    B100, Z100&lt;BR /&gt;
    3     127    H119, J112, Z100&lt;BR /&gt;
   */&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 22 Sep 2010 14:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73792#M15902</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-22T14:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Delimited String from Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73793#M15903</link>
      <description>Thanks guys, It appears i was closer then i originally thought.&lt;BR /&gt;
All sorted!</description>
      <pubDate>Wed, 22 Sep 2010 23:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimited-String-from-Dataset/m-p/73793#M15903</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-22T23:25:42Z</dc:date>
    </item>
  </channel>
</rss>

