<?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: Trying to concatenate strings from multiple obs into 1 obs. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/290551#M59758</link>
    <description>Data task;&lt;BR /&gt;Input ID ONum notes &amp;amp; $ 30.;&lt;BR /&gt;cards;&lt;BR /&gt;11 10001 This is a Test&lt;BR /&gt;11 10001 of SAS&lt;BR /&gt;11 10002 Today the weather was good&lt;BR /&gt;11 10002 Busy Shopping&lt;BR /&gt;44 19999 Fishing&lt;BR /&gt;55 77777 Working on car&lt;BR /&gt;55 77777 Hunting&lt;BR /&gt;55 77777 Swimming&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data task_final;&lt;BR /&gt;retain id onum ;&lt;BR /&gt;length new $ 50;&lt;BR /&gt;do until (last.onum);&lt;BR /&gt;set task;&lt;BR /&gt;by onum;&lt;BR /&gt;new=catx(" ",new,notes);&lt;BR /&gt;end;&lt;BR /&gt;Keep ID ONum new;&lt;BR /&gt;run;</description>
    <pubDate>Tue, 09 Aug 2016 19:30:46 GMT</pubDate>
    <dc:creator>ravi_mandal</dc:creator>
    <dc:date>2016-08-09T19:30:46Z</dc:date>
    <item>
      <title>Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73534#M21313</link>
      <description>Hello to all,&lt;BR /&gt;
I've run into an issue that I need a bit of help with.&lt;BR /&gt;
&lt;BR /&gt;
I have a table that has a ID, ONum, notes columns.&lt;BR /&gt;
What i'm trying to do concatenate every notes obs into one obs based on similer&lt;BR /&gt;
ID &amp;amp; ONum with a space inbetween every concatenation.&lt;BR /&gt;
&lt;BR /&gt;
ID ONum notes&lt;BR /&gt;
--  --------- ----------&lt;BR /&gt;
11 10001 "This is a Test"&lt;BR /&gt;
11 10001 " of SAS"&lt;BR /&gt;
11 10002 "Today the weather was good"&lt;BR /&gt;
11 10002 "Busy Shopping"&lt;BR /&gt;
44 19999 "Fishing"&lt;BR /&gt;
55 77777 "Working on car"&lt;BR /&gt;
55 77777 "Hunting"&lt;BR /&gt;
55 77777 "Swimming"&lt;BR /&gt;
&lt;BR /&gt;
After data step I need the data to look like this&lt;BR /&gt;
&lt;BR /&gt;
ID ONum notes&lt;BR /&gt;
--  --------- ----------&lt;BR /&gt;
11 10001 "This is a Test of SAS"&lt;BR /&gt;
11 10002 "Today the weather was good Busy Shopping"&lt;BR /&gt;
44 19999 "Fishing"&lt;BR /&gt;
55 77777 "Working on car Hunting Swimming"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you to anyone who can help</description>
      <pubDate>Mon, 28 Sep 2009 18:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73534#M21313</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2009-09-28T18:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73535#M21314</link>
      <description>One approach:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=test out=sorted;&lt;BR /&gt;
by id Onum;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data concat;&lt;BR /&gt;
length total_notes $ 200 /* need to be the max */;&lt;BR /&gt;
	set sorted;&lt;BR /&gt;
	by ID ONum;&lt;BR /&gt;
&lt;BR /&gt;
	retain total_notes;&lt;BR /&gt;
&lt;BR /&gt;
	if first.Onum then total_notes = notes;&lt;BR /&gt;
	else&lt;BR /&gt;
		total_notes=trim(total_notes) || ' ' || trim(notes);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
	if last.ONum then output;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 28 Sep 2009 18:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73535#M21314</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-28T18:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73536#M21315</link>
      <description>kmg,&lt;BR /&gt;
Thank you so much I think that did it.  &lt;BR /&gt;
&lt;BR /&gt;
Do you know if there is a way to put a return between the notes?&lt;BR /&gt;
&lt;BR /&gt;
Currently the field is defined as length notes $32767.  If the field is defined as that big is there anything bigger?  I have no control over the field size i'm just afraid that if they have 4 rows that have almost that many characters what will happen when it tries to concatenate them?&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for all your help</description>
      <pubDate>Mon, 28 Sep 2009 18:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73536#M21315</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2009-09-28T18:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73537#M21316</link>
      <description>Jerry:&lt;BR /&gt;
&lt;BR /&gt;
Assume that your data is in a table called temp. First step is to transpose the data.&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=temp out=trans;&lt;BR /&gt;
  var notes;&lt;BR /&gt;
	by id onum;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Second step is to use the catx function to concatenate the columns. &lt;BR /&gt;
&lt;BR /&gt;
data trans;&lt;BR /&gt;
  set trans;&lt;BR /&gt;
	new_notes=catx(' ',col1,col2,col3);&lt;BR /&gt;
	keep id onum new_notes;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The issue for a program is to determine the maximum frequency for the id onum combination. This could be done in a macro to specify the number of col arguments for CATX</description>
      <pubDate>Mon, 28 Sep 2009 18:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73537#M21316</guid>
      <dc:creator>barheat</dc:creator>
      <dc:date>2009-09-28T18:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73538#M21317</link>
      <description>Barheat,&lt;BR /&gt;
Thank you so much for your help.  I'm going to try what you suggested.&lt;BR /&gt;
&lt;BR /&gt;
Thank You</description>
      <pubDate>Mon, 28 Sep 2009 18:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73538#M21317</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2009-09-28T18:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73539#M21318</link>
      <description>Note that the Proc Transpose approach as given assumes that you can specify what the maximum number of strings will be (in your example, it was 3, but it may vary from data set to data set).  It would be better to switch to using an array to avoid this limitation.</description>
      <pubDate>Mon, 28 Sep 2009 19:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73539#M21318</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-28T19:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73540#M21319</link>
      <description>kmg,&lt;BR /&gt;
I was just going to post a question about that.&lt;BR /&gt;
I'm going to stick with you example for now.  It seems to be working good for now.&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much to both of you.</description>
      <pubDate>Mon, 28 Sep 2009 19:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73540#M21319</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2009-09-28T19:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73541#M21320</link>
      <description>While using the PROC TRANSPOSE approach, precede the PROC execution with a DATA step that counts and increments a variable every "n" times, then you have flexibility controlling the transposed observation range.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 28 Sep 2009 21:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73541#M21320</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-28T21:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73542#M21321</link>
      <description>The idea to PROC TRANSPOSE and CATX is good because you don't need to know HOW MANY.  Also CATX will print warning if the concatenation will not fit in the variable, see example below.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   input ID:$2. ONum:$5. notes &amp;amp;$quote64.;&lt;BR /&gt;
   cards;&lt;BR /&gt;
11 10001 "This is a Test"&lt;BR /&gt;
11 10001 " of SAS"&lt;BR /&gt;
11 10002 "Today the weather was good"&lt;BR /&gt;
11 10002 "Busy Shopping"&lt;BR /&gt;
44 19999 "Fishing"&lt;BR /&gt;
55 77777 "Working on car"&lt;BR /&gt;
55 77777 "Hunting"&lt;BR /&gt;
55 77777 "Swimming"&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc transpose out=wide(drop=_name_);&lt;BR /&gt;
   by id onum;&lt;BR /&gt;
   var notes;&lt;BR /&gt;
   run;&lt;BR /&gt;
data wide;&lt;BR /&gt;
   length note $35; *To test overrun;&lt;BR /&gt;
   set wide;&lt;BR /&gt;
   note = catx(' ',of col:);&lt;BR /&gt;
   drop col:;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 29 Sep 2009 13:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73542#M21321</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-09-29T13:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73543#M21322</link>
      <description>&amp;gt; kmg,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Do you know if there is a way to put a return between&lt;BR /&gt;
&amp;gt; the notes?&lt;BR /&gt;
&lt;BR /&gt;
From the first response modify: &lt;BR /&gt;
&lt;BR /&gt;
if last.ONum then output;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
To:&lt;BR /&gt;
if last.ONum then do;&lt;BR /&gt;
  output;&lt;BR /&gt;
  total_notes= ""; &lt;BR /&gt;
  output;/* this puts a blank value for the note field, insert appropriate character code if you want an actual return character */&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Currently the field is defined as length notes&lt;BR /&gt;
&amp;gt; $32767.  If the field is defined as that big is there&lt;BR /&gt;
&amp;gt; anything bigger?  I have no control over the field&lt;BR /&gt;
&amp;gt; size i'm just afraid that if they have 4 rows that&lt;BR /&gt;
&amp;gt; have almost that many characters what will happen&lt;BR /&gt;
&amp;gt; when it tries to concatenate them?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&lt;BR /&gt;
No clue but some create use of a FILE statement and PUT with @ and @@ may create a text file without that size limitation.</description>
      <pubDate>Thu, 01 Oct 2009 19:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/73543#M21322</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2009-10-01T19:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to concatenate strings from multiple obs into 1 obs.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/290551#M59758</link>
      <description>Data task;&lt;BR /&gt;Input ID ONum notes &amp;amp; $ 30.;&lt;BR /&gt;cards;&lt;BR /&gt;11 10001 This is a Test&lt;BR /&gt;11 10001 of SAS&lt;BR /&gt;11 10002 Today the weather was good&lt;BR /&gt;11 10002 Busy Shopping&lt;BR /&gt;44 19999 Fishing&lt;BR /&gt;55 77777 Working on car&lt;BR /&gt;55 77777 Hunting&lt;BR /&gt;55 77777 Swimming&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data task_final;&lt;BR /&gt;retain id onum ;&lt;BR /&gt;length new $ 50;&lt;BR /&gt;do until (last.onum);&lt;BR /&gt;set task;&lt;BR /&gt;by onum;&lt;BR /&gt;new=catx(" ",new,notes);&lt;BR /&gt;end;&lt;BR /&gt;Keep ID ONum new;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 09 Aug 2016 19:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-concatenate-strings-from-multiple-obs-into-1-obs/m-p/290551#M59758</guid>
      <dc:creator>ravi_mandal</dc:creator>
      <dc:date>2016-08-09T19:30:46Z</dc:date>
    </item>
  </channel>
</rss>

